javascript for loop of code example
Example 1: for of js
let list = [4, 5, 6];
for (let i in list) {
console.log(i);
}
for (let i of list) {
console.log(i);
}
Example 2: for loop javascript
var listItem = [
{name: 'myName1', gender: 'male'},
{name: 'myName2', gender: 'female'},
{name: 'myName3', gender: 'male'},
{name: 'myName4', gender: 'female'},
]
for (const iterator of listItem) {
console.log(iterator.name+ ' and '+ iterator.gender);
}
Example 3: for of loop javascript
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}
Example 4: for javascipt
for (let i = 0; i < 9; i++) {
str = str + i;
}