Answers for "how to access object data inside array in javascript using for loop"

1

javascript loop through array of objects

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

for (var elm of arr) {
  console.log(elm);
}
Posted by: Guest on October-04-2020
0

how to get value in array object value using for loop in javascript

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

const sum = myArray.map(element => element.x).reduce((a, b) => a + b, 0);
console.log(sum); // 600 = 0 + 100 + 200 + 300

const average = sum / myArray.length;
console.log(average); // 200
Posted by: Guest on May-11-2020
-1

iterate over array of object javascript and access the properties

for (let item of items) {
    console.log(item); // Will display contents of the object inside the array
}
Posted by: Guest on April-29-2020

Code answers related to "how to access object data inside array in javascript using for loop"

Code answers related to "Javascript"

Browse Popular Code Answers by Language