Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!