How to use the for of statement of JavaScript
This article mainly explains "how to use JavaScript's for of statement". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "how to use JavaScript's for of statement" together.
JavaScript for of statement loops over iterable object values
It allows you to loop through iterable data structures such as arrays, strings, maps, node lists, etc.:
syntax
for (variable of iterable) {
// code block to be executed
}
variable -For each iteration, the value of the next attribute is assigned to the variable. Variables can be declared with const, let, or var.
iterable -An object with iterable attributes.
walk the array
examples
const cars = ["BMW", "Volvo", "Mini"];
let text = "";
for (let x of cars) {
text += x;
}
give it a try
traversal string
examples
let language = "JavaScript";
let text = "";
for (let x of language) {
text += x;
}
Thank you for reading, the above is the content of "how to use JavaScript's for of statement", after learning this article, I believe everyone has a deeper understanding of how to use JavaScript's for of statement, and the specific use situation still needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!