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

277
Visualizações
array.includes( () => {} ) as a function

Is there a method like includes that only searches for an element in an array but allows you to see the elements that are being iterating on?

for example: I have the following array:

const arr = [{ color: 'red' },{ color: 'blue' },{ color: 'pink' },{ color: 'green' }]

I want to check if the arr holds an element with the value of pink: so I thought if there's something like this in JavaScript:

arr.includes( (el, index)=> el.color == 'pink' )

which then returns a boolean, either true or false.

Is there a method like that in JavaScript? if not, what about lodash?

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

0

I think you want find:

if (arr.find(el => el.color === "pink")) console.log("it's there");
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