How to loop through an array containing objects and access their properties 1

How to loop through an array containing objects and access their properties

yourArray.forEach(function (arrayItem) {
    var x = arrayItem.prop1 + 2;
    console.log(x);
});

Here is what the above code is Doing:
1. We create an array called myArray.
2. We use the forEach() method to loop through each item in the array.
3. We pass a function into the forEach() method.
4. The function takes one parameter, which is the array item.
5. We add 2 to the array item and store it in a variable called x.
6. We log the value of x to the console.

Similar Posts