“JavaScript Foreach Array of Objects” Kode Jawaban

Iterasi array javascript

array = [ 1, 2, 3, 4, 5, 6 ]; 
for (index = 0; index < array.length; index++) { 
    console.log(array[index]); 
} 
Mandras Tree Shrew

Indeks Foreach JavaScript

users.forEach((user, index)=>{
	console.log(index); // Prints the index at which the loop is currently at
});
Concerned Chipmunk

JavaScript Foreach Array of Objects

const people = [ {name: "john", age:23},
                {name: "john", age:43},
                {name: "jim", age:101},
                {name: "bob", age:67} ];

const john = people.find(person => person.name === 'john');
console.log(john);
Successful Seal

JavaScript Foreach 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
Successful Seal

JavaScript Foreach Array of Objects

const people = [
  { name: "John", age: 21 },
  { name: "Peter", age: 31 },
  { name: "Andrew", age: 29 },
  { name: "Thomas", age: 25 }
];

let sortByAge = people.sort(function (p1, p2) {
  return p1.age - p2.age;
});

console.log(sortByAge);
Successful Seal

JavaScript Foreach Array of Objects

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
Successful Seal

Jawaban yang mirip dengan “JavaScript Foreach Array of Objects”

Pertanyaan yang mirip dengan “JavaScript Foreach Array of Objects”

Lebih banyak jawaban terkait untuk “JavaScript Foreach Array of Objects” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya