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

198
Vistas
Find specific JSON key and return its value in Javascript

I have some JSON from an API which I am logging in the console. This is easy for something like the id where I can do this...

let movieID = out.id;
console.log(movieID)

But how can I also return the 'name' of the person whose job is specifically 'Director' from JSON example like this? Basically I need to do something like 'if someone has the JOB of DIRECTOR, log their name to the console.

{
    "id": 37291,
    "credits": {
        "crew": [
            {
                "name": "John Smith",
                "job": "Producer"
            },
            {
                "name": "Mary Jones",
                "job": "Director"
            }
        ]
    }
}
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can get the list of the crew, like you described above. Then find the first entry in that list where the job equals "Director" and put it in a variable:

let director = out.credits.crew.find(member => member.job == "Director");

You can then log the data, as you did for the movie itself.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Something like this would do literally what you asked which was to console log out the names

credits.crew.foreach((crewMember) => {
    if (crewMember.job == 'Director') {
      console.log(crewMember.name)
    }
  })
about 4 years ago · Juan Pablo Isaza Denunciar

0

Use underscore:

_.filter(credits.crew, (key) => key.job === 'Director')

That will give you all the keys with that value. Trust me you should use underscore or lodash because objects can get super tricky and it saves you a ton of time.

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