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

146
Vistas
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 Respuestas
Responde la pregunta

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 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