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

158
Vistas
How to find particular id using iterate Object in JavaScript

i'm trying to iterate this object with the help of for each How to find particular id using iterating object and supposed we want to

if(id == 12) {
   return true;
}else{
   return false;
}

This is a object

const data = {
    "service": [
        "BUSINESS",
        "LEGAL",
        "FINANCE",
        "ADVERTISEMENT"
    ],
    "service1": [
        { "id": 1 },
        { "id": 2 },
        { "id": 3 },
        { "id": 4 },
    ],
    "service2": [
        { "id": 5 },
        { "id": 6 },
        { "id": 7 },
        { "id": 8 },
    ],
    "service3": [
        { "id": 9 },
        { "id": 10 },
        { "id": 11 },
        { "id": 12 },
    ],
    "service4": [
        { "id": 13 },
        { "id": 14 },
        { "id": 15 },
        { "id": 16 },
    ],
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First, you check iterated object structure. If it contains array of object's or array of string's. Then find an object with ID which you need.

const data = {
  service: ["BUSINESS", "LEGAL", "FINANCE", "ADVERTISEMENT"],
  service1: [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }],
  service2: [{ id: 5 }, { id: 6 }, { id: 7 }, { id: 8 }],
  service3: [{ id: 9 }, { id: 10 }, { id: 11 }, { id: 12 }],
  service4: [{ id: 13 }, { id: 14 }, { id: 15 }, { id: 16 }]
};

Object.entries(data).forEach(([_, value]) => {
  if (value.every((item) => typeof item === "object")) {
    if (value.find((item) => item.id === 12)) {
      // do your action
    } 
  }
});

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