“JavaScript Foreach tablic obiektów” Kod odpowiedzi

Iteracja tablicy JavaScript

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

indeks JavaScript Foreach

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

JavaScript Foreach tablic obiektów

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 tablic obiektów

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 tablic obiektów

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 tablic obiektów

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

Odpowiedzi podobne do “JavaScript Foreach tablic obiektów”

Pytania podobne do “JavaScript Foreach tablic obiektów”

Więcej pokrewnych odpowiedzi na “JavaScript Foreach tablic obiektów” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu