“Buscar elemento en Array JavaScript” Código de respuesta

Buscar JavaScript de matriz

let arr = [
    { name:"string 1", value:"this", other: "that" },
    { name:"string 2", value:"this", other: "that" }
];

let obj = arr.find(o => o.name === 'string 1');

console.log(obj);
Energetic Eland

Buscar elemento en Array JavaScript

const simpleArray = [3, 5, 7, 15];
const objectArray = [{ name: 'John' }, { name: 'Emma' }]

console.log( simpleArray.find(e => e === 7) )
// expected output 7

console.log( simpleArray.find(e => e === 10) )
// expected output undefined

console.log( objectArray.find(e => e.name === 'John') )
// expected output { name: 'John' }
Inquisitive Impala

JavaScript encontrar

const inventory = [
  {name: 'apples', quantity: 2},
  {name: 'cherries', quantity: 8}
  {name: 'bananas', quantity: 0},
  {name: 'cherries', quantity: 5}
  {name: 'cherries', quantity: 15}
  
];

const result = inventory.find( ({ name }) => name === 'cherries' );

console.log(result) // { name: 'cherries', quantity: 5 }
Real Rattlesnake

encontrar en la función de matriz

const persons = [
  {name:"Shirshak",gender:"male"},
  {name:"Amelia",gender:"female"},
  {name:"Amand",gender:"male"}
]
//filter return all objects in array
let male = persons.filter(function(person){
return person.gender==='male'
})
console.log(male) //[{name:"Shirshak",gender:"male"},{name:"Amand",gender:"male"}]

//find return first object that match condition
let female = persons.find(function(person){
return person.gender==='female'
})
Sab Tech

JavaScript Array.Encentable

const array1 = [5, 12, 8, 130, 44];

const found = array1.find(element => element > 10);

console.log(found);
// expected output: 12
Amused Albatross

Matriz encontrar

const array1 = [5, 12, 8, 130, 44];

const found = array1.find(element => element > 10);

console.log(found);
// expected output: 12
Creepy Gábor

Respuestas similares a “Buscar elemento en Array JavaScript”

Preguntas similares a “Buscar elemento en Array JavaScript”

Más respuestas relacionadas con “Buscar elemento en Array JavaScript” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código