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
1var person={
2 first_name:"johnny",
3 last_name: "johnson",
4 phone:"703-3424-1111"
5};
6for (var property in person) {
7 console.log(property,":",person[property]);
8}
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]
1var array = ["e", 5, "cool", 100];
2
3for (let i = 0; i < array.length; i++) {
4 console.log(array[i]);
5}
6
7// This is a common method used to loop through elements in arrays.
8// You can use this to change elements, read them, and edit them