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 });
var people=[ {first_name:"john",last_name:"doe"}, {first_name:"mary",last_name:"beth"} ]; for (let i = 0; i < people.length; i++) { console.log(people[i].first_name); }
yourArray.forEach(function (arrayItem) { var x = arrayItem.prop1 + 2; console.log(x); });
const myArray = [{x:100}, {x:200}, {x:300}]; const newArray= myArray.map(element => element.x); console.log(newArray); // [100, 200, 300]
const myArray = [{x:100}, {x:200}, {x:300}]; const newArray= myArray.map(element => { return { ...element, x: element.x * 2 }; }); console.log(myArray); // [100, 200, 300] console.log(newArray); // [200, 400, 600]
const people = [ {name: 'John', age: 23}, {name: 'Andrew', age: 3}, {name: 'Peter', age: 8}, {name: 'Hanna', age: 14}, {name: 'Adam', age: 37}]; const anyAdult = people.some(person => person.age >= 18); console.log(anyAdult); // true