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

145
Visualizações
How to check if the array inside object has elements of interest?

Hi i have an object like so,

const obj = {
    id: '1',
    itemData: [
        "type1",
        "type2",
        "type3",
    ],
}

sometimes this itemData array can be empty array.

now i have to check if itemData has "type1" or "type2". if so then should return true if not false.

i have tried like below,

const isDisabled = obj.itemData.map(e => return e === "type1" || e==="type2")

but this doesnt work. could someone help me with this. thanks.

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

0

You can use includes with some

const obj = {
    id: '1',
    itemData: [
        "type1",
        "type2",
        "type3",
    ],
}

console.log(!obj.itemData.length || obj.itemData.some(el => ['type1', 'type2'].includes(el)));

The some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns true if, in the array, it finds an element for which the provided function returns true; otherwise it returns false. It doesn't modify the array.

MDN - some

The includes() method determines whether an array includes a certain value among its entries

MDN - includes

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