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

168
Views
Accessing a value from a nested array in JSON
const data = fs.readFileSync('./movies.JSON');
data.toString();
var obj = JSON.parse(data);
console.log(Object.values(obj.moviesList));

This is my js file. This prints all keys and pairs of my JSON file. I am trying to access the nested array in the JSON file. I have tried console.log(Object.values(obj.moviesList.actors==="206'));

And a bunch of other variations.

    "moviesList":[
    {
        "movieId": 4192148,
        "title": "Highly Functional",
        "actors": [
            3188187,
            3306943,
            132257,
            47265
        ]
    },

here is a small snippet of my JSON file containing nested arrays.

I want to start out by printing out all movie Id's that have an actor whose id is 206.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you are scanning a nested array, here's one way to about that using includes to check the actors array.

const moviesList = [{
    "movieId": 4192148,
    "title": "Highly Functional",
    "actors": [
      3188187,
      3306943,
      132257,
      47265
    ]
  },
  {
    "movieId": 11111,
    "title": "Highly Functional2",
    "actors": [
      3188187,
      3306943,
      206,
      47265
    ]
  },
  {
    "movieId": 11112,
    "title": "Highly Functional3",
    "actors": [
      3188187,
      3306943,
      206,
      47265
    ]
  }
];

let matches = [];
for (const movie of moviesList) {
  const { actors, movieId } = movie;
  if (actors.includes(206)) {
    matches.push(movieId);
  }
}

console.log(matches);

// Another format

matches = moviesList
  .filter(({ actors }) => actors.includes(206))
  .map(({ movieId }) => movieId)
  
  
console.log(matches);

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!