1/* new options with IE6: loop through array of objects */
2
3const people = [
4 {id: 100, name: 'Vikash'},
5 {id: 101, name: 'Sugam'},
6 {id: 102, name: 'Ashish'}
7];
8
9// using for of
10for (let persone of people) {
11 console.log(persone.id + ': ' + persone.name);
12}
13
14// using forEach(...)
15people.forEach(person => {
16 console.log(persone.id + ': ' + persone.name);
17});
18// output of above two methods
19// 100: Vikash
20// 101: Sugam
21// 102: Ashish
22
23
24// forEach(...) with index
25people.forEach((person, index) => {
26 console.log(index + ': ' + persone.name);
27});
28// output of above code in console
29// 0: Vikash
30// 1: Sugam
31// 2: Ashish
32
1let arr = [object0, object1, object2];
2
3for (let elm of arr) {
4 console.log(elm);
5}
1var people=[
2 {first_name:"john",last_name:"doe"},
3 {first_name:"mary",last_name:"beth"}
4];
5for (let i = 0; i < people.length; i++) {
6 console.log(people[i].first_name);
7}
1const myArray = [{x:100}, {x:200}, {x:300}];
2
3const newArray= myArray.map(element => element.x);
4console.log(newArray); // [100, 200, 300]
1const people = [
2 {name: 'John', age: 23},
3 {name: 'Andrew', age: 3},
4 {name: 'Peter', age: 8},
5 {name: 'Hanna', age: 14},
6 {name: 'Adam', age: 37}];
7
8const anyAdult = people.some(person => person.age >= 18);
9console.log(anyAdult); // true
1yourArray.forEach(function (arrayItem) {
2 var x = arrayItem.prop1 + 2;
3 console.log(x);
4});