“JavaScript Foreach Array объектов” Ответ

Itater Array JavaScript

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

JavaScript Foreach Index

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

JavaScript Foreach Array объектов

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 объектов

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 объектов

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 объектов

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

Ответы похожие на “JavaScript Foreach Array объектов”

Вопросы похожие на “JavaScript Foreach Array объектов”

Больше похожих ответов на “JavaScript Foreach Array объектов” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования