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

125
Vistas
How do i filter a value of key in an object based on matching value?

I have an object that contains objects. How do i filter out the value of "title" based on whether the id is matching?

{
    "0": {
        "id": 1912,
        "title": "Fiction",
    },
    "1": {
        "id": 1957,
        "title": "Non-Fiction",
    },
    "2": {
        "id": 1958,
        "title": "Literature",
    },
}

For example, if the const id=1958, then the output: Literature

Output:

Literature
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can try this:

let data = {
    "0": {
        "id": 1912,
        "title": "Fiction",
    },
    "1": {
        "id": 1957,
        "title": "Non-Fiction",
    },
    "2": {
        "id": 1958,
        "title": "Literature",
    },
};

let getTitle = (obj, id)=>{
 return Object.values(obj).filter(x=>x.id===id)?.[0]?.title
};

console.log(getTitle(data,1958))

You can also use find instead of filter.

Without optional chaining as per OPs comment:

   let data = {
        "0": {
            "id": 1912,
            "title": "Fiction",
        },
        "1": {
            "id": 1957,
            "title": "Non-Fiction",
        },
        "2": {
            "id": 1958,
            "title": "Literature",
        },
    };

    let getTitle = (obj, id)=>{
      let element = Object.values(obj).find(x=>x.id===id);
      return element ? element.title : "";
    };

    console.log(getTitle(data,1958))

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