Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda