for-of loop

JavaScript brought us the forEach construct for looping through collections. It is a great built-in method to use, but you can't break out of this loop. We also have the for-in loop, which is great for objects with keys that are strings, but it has some drawbacks when iterating through arrays.

Enter the new for-of loop. It works well for objects, arrays, and maps, and you can break out of it. Here is the syntax, which is identical to that for the for-in loop, other than changing in to of:

let myArray = [5, 10, 15, 20, 25;
for (var item of myArray) {
console.log(item);
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.160.181