- Hands-On Machine Learning with JavaScript
- Burak Kanber
- 79字
- 2021-06-25 21:38:19
The for...of function
The for loops over arrays in ES5 are often achieved using the for (index in array) syntax, which looks something like this:
var items = [1, 2, 3 ];
for (var index in items) {
var item = items[index];
…
}
And ES6 adds the for...of syntax, which saves you a step, as you can see from the following code:
const items = [1, 2, 3 ];
for (const item of items) {
…
}