Here is an example
arr1 = [{ b: 2 }, { a: 1 }]
arr1.forEach(function (element, index, array) {
console.log(element);
console.log('of');
console.log(array);
console.log('');
arr1.push({ c: 3 });
});
console.log(arr1);
Result
{ b: 2 }
of
[ { b: 2 }, { a: 1 } ]
{ a: 1 }
of
[ { b: 2 }, { a: 1 }, { c: 3 } ]
[ { b: 2 }, { a: 1 }, { c: 3 }, { c: 3 } ]
In the above example, I look at the array and add more values to it, and they are added to the original, and the loop
Does forEachanother loop use for loop?
source
share