Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

82
Vistas
search for a specific property in array of objects and return boolean

lets say i have an array of objects

    let arr = [
  {
    name: "john",
    age: 22
  },
  {
    name: "george",
    age: 55
  }
];

and an object

  let obj = {
    name: "bill",
    age: 55
  }

and i want to search all arr objects to find anyone with the same age as obj.age and return a boolean depending whether it includes a same property or not.

i can obviously do :

let find = arr.filter(i => i.age === obj.age);
let bool = find.length > 0 && true;

but is there a way to call a method (lodash,plain js or whatever) to just get this by design like method(arr,obj.age) //returns true ?

let arr = [
  {
    name: "john",
    age: 22
  },
  {
    name: "george",
    age: 55
  }
];

let obj = {
  name: "bill",
  age: 55
}

let find = arr.filter(i => i.age === obj.age);
let bool = find.length > 0 && true;

console.log(bool)

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use some. So basically it will return a boolean value if any of the object property in array matches the required value

let arr = [{
    name: "john",
    age: 22
  },
  {
    name: "george",
    age: 55
  }
];
let obj = {
  name: "bill",
  age: 55
}

const val = arr.some(item => item.age === obj.age);
console.log(val)

about 4 years ago · Juan Pablo Isaza Denunciar

0

we can do it in two ways. we can use the some function and get the boolean directly or by find function, we can convert it to a boolean using !! operator.

let arr = [{
    name: "john",
    age: 22
  },
  {
    name: "george",
    age: 55
  }
];
let obj = {
  name: "bill",
  age: 55
}

const val1 = arr.some(item => item.age === obj.age);
console.log(val1)
const val2 = !!arr.find(item => item.age === obj.age);
console.log(val2)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda