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

245
Vistas
How can I use .some() to find if an array of objects contains a specific property value

I've an array containing objects, where every object represents a person that's going to a video theatre. The objects contains properties such as Name, Age and Hobby. If there is (atleast) one person younger than 18, the variable censor should be set to true.

My code below yields the value false, despite Tim being younger than 18. Is it not possible to use .some() this way, or what am I doing wrong?

var persons = [
    {Name: "Joel", Age:25, Hobby:"Fishing"},
    {Name: "Michael", Age:31, Hobby:"Astronomy"},
    {Name: "Tim", Age:12, Hobby:"Video Games"},
]

var censor = persons.some((person) => {person.Age < 18})
console.log(censor) --> false
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

It's

var censor = persons.some((person) => person.Age < 18); // <-- no curly brackets for the predicate

instead of {person.Age < 18}

about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to remove the brackets.

var persons = [
    {Name: "Joel", Age:25, Hobby:"Fishing"},
    {Name: "Michael", Age:31, Hobby:"Astronomy"},
    {Name: "Tim", Age:12, Hobby:"Video Games"},
]

var censor = persons.some((person) => person.Age < 18)
console.log(censor)

If you want to continue using brackets, then you need to add return to the statement:

var censor = persons.some((person) => {
  return person.Age < 18
})
about 4 years ago · Juan Pablo Isaza Denunciar

0

You are missing a return in your callback that is why it is always false,

either use:

var censor = persons.some(person => person.Age < 18)

or

var censor = persons.some(person => {return person.Age < 18 })
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