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

98
Vistas
Search javascript object to return the relevant catId

I have the following javascript array and I am trying to simply return the catId for an id - for instance if I search for the id of 10000356 I want to return the value of 4. How should I do this?

categoryIds = [
    {
        "id": 10000282,
        "catId": 0
    },
    {
        "id": 10000340,
        "catId": 0
    },
    {
        "id": 10000341,
        "catId": 0
    },
    {
        "id": 10000334,
        "catId": 1
    },
    {
        "id": 10000333,
        "catId": 2
    },
    {
        "id": 10000336,
        "catId": 2
    },
    {
        "id": 10000337,
        "catId": 3
    },
    {
        "id": 10000356,
        "catId": 4
    }
]
categoryIds.filter(id => id == 10000356);

Expected outcome :

4 - the catId for `10000356` is the integer 4.
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

const result = categoryIds.find((data) => data?.id === 10000356); // beware result can be null
// use ?. to avoid error if data is null
// rembere that you have an array of object not of id ;)
console.log("the catId for 10000356 is the integer " + result?.catId);

use find if you are sure that the id are unique and I think it's the case here. find will return the data you want and return null if not found

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