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

134
Vistas
How to get certain property of object when using filter

I have an array of objects

const array = [
  {a: 1, b:4},
  {a: 2, b:5},
  {a: 3, b:6},
]

And i need to find one element in array and recieve only a certain value of object's property. But how can i do it with filter. I tried to do it this way This one didn't work

  const b_Value = array.filter(element => element.a === 3).b

Is it possible do get value in filter, not element itself? Also i tried to use if and return but it didnt work also

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

0

.filter() returns an array, not a single element. You could index that array:

const b_Value = array.filter(element => element.a === 3)[0].b;

Or perhaps use .find():

const b_Value = array.find(element => element.a === 3).b;

Of course, in either case you'll want to define how you should handle it if (1) no results match or (2) multiple results match.

For example, you might use optional chaining for the possibility of no matching results:

const b_Value = array.find(element => element.a === 3)?.b;

In which case b_Value could be null.

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