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

138
Visualizações
How to check if a certain value exist in an array which holds objects as its elements. JavaScript

The first one is when we have an array holds regular elements like strings and I know how to use Includes on it.

But how about arrays holding objects as their element? How can I check if there is a certain value in those objects?

const arr = ['this', 'is', 'a test'];

console.log(arr.includes('this'));

const arr2 = [
  { id: '123', name: 'Alex' },
  { id: '345', name: 'Dan' },
  { id: '33', name: 'Joe' },
];

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use the some function.

const arr2 = [
  { id: '123', name: 'Alex' },
  { id: '345', name: 'Dan' },
  { id: '33', name: 'Joe' },
];

console.log(arr2.some(item => item.name==="this" ))

The some() method tests whether at least one element in the array passes the test implemented by the provided function.

about 4 years ago · Juan Pablo Isaza Relatório

0

if you want a returned array of values that match = >

 const filtered = arr2.filter((item)=>item.name == 'value')

if you want bool(true||false) =>

 const filtered = arr2.filter((item)=>item.name == 'value').length > 0

or using some as mentioned above.

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