apply loop in array objects javascript code example

Example 1: javascript loop through array of objects

let arr = [object0, object1, object2];

for (let elm of arr) {
  console.log(elm);
}

Example 2: loop array of objects

const myArray = [{x:100}, {x:200}, {x:300}];

myArray.forEach((element, index, array) => {
    console.log(element.x); // 100, 200, 300
    console.log(index); // 0, 1, 2
    console.log(array); // same myArray object 3 times
});

Example 3: javascript loop through array of objects

var arr = [{id: 1},{id: 2},{id: 3}];

for (var elm of arr) {
  console.log(elm);
}

Example 4: how to loop through an array of objects+

var arr = [[1,2], [3,4], [5,6]];
 for (var i=0; i < arr.length; i++) {
  for (var j=0; j < arr[i].length; j++) {
    console.log(arr[i][j]);
  }
}