MDN for of loop code example
Example 1: javascript loop
let array = ['Item 1', 'Item 2', 'Item 3'];
for (let index = 0; index < array.length; index++) {
console.log(array[index]);
}
for (let index in array) {
console.log(array[index]);
}
for (let value of array) {
console.log(value);
}
array.forEach((value, index) => {
console.log(index);
console.log(value);
});
Example 2: javascript for loop
for (let count = 0; count < 90; count++) {
}
Example 3: use these instead of a for loop javascript
const array = [1, 2, 3];array.forEach(function(elem, index, array) { array[index] = elem * 2;});console.log(array);
Example 4: for of mdn
let iterable = new Map([["a", 1], ["b", 2], ["c", 3]]);
for (let entry of iterable) {
console.log(entry);
}
for (let [key, value] of iterable) {
console.log(value);
}
Example 5: for of mdn
let iterable = new Uint8Array([0x00, 0xff]);
for (let value of iterable) {
console.log(value);
}