Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

197
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda