Answers for "iterate through array object javascript"

8

javascript loop through array of objects es6

/* new options with IE6: loop through array of objects */

const people = [
  {id: 100, name: 'Vikash'},
  {id: 101, name: 'Sugam'},
  {id: 102, name: 'Ashish'}
];

// using for of
for (let persone of people) {
  console.log(persone.id + ': ' + persone.name);
}

// using forEach(...)
people.forEach(person => {
 console.log(persone.id + ': ' + persone.name);
});
// output of above two methods
// 100: Vikash
// 101: Sugam
// 102: Ashish


// forEach(...) with index
people.forEach((person, index) => {
 console.log(index + ': ' + persone.name);
});
// output of above code in console
// 0: Vikash
// 1: Sugam
// 2: Ashish
Posted by: Guest on May-04-2020
53

javascript iterate over object

var person={
 	first_name:"johnny",
  	last_name: "johnson",
	phone:"703-3424-1111"
};
for (var property in person) {
  	console.log(property,":",person[property]);
}
Posted by: Guest on July-22-2019
2

javascript object array iteration

let obj = {
  key1: "value1",
  key2: "value2",
  key3: "value3"
}

Object.keys(obj).forEach(key => {
  let value = obj[key];
  //use key and value here
});
Posted by: Guest on May-01-2020
0

loop array of objects

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
Posted by: Guest on May-11-2020
0

javascript loop through array of objects

//Only to be used if you need the numbers
var array = new Array(item1,item2,item3)

for(i=0;i<array.length;i++){
  if(i==2){
    console.log(array[i])
  }
}
Posted by: Guest on March-07-2020

Code answers related to "iterate through array object javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language