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

105
Views
Read the list of Ids from nested JSON

I need to read the ids from nested loop using Javascript.

Input:

let data = [3,[{
"Id": 30,
"Name":"John"
},{
"Id": 33,
"Name":"Jill"
},{
"Id": 34,
"Name":"Jerena"
}]]

Output:

[30,33,34]

I'm stuck with this from sometime. Using maps let Ids = [data[0][1]].map(a => a.Id);

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

0

Try this

let data = [3,[{
"Id": 30,
"Name":"John"
},{
"Id": 33,
"Name":"Jill"
},{
"Id": 34,
"Name":"Jerena"
}]]

console.log(data[1].map(r => r.Id))

about 4 years ago · Juan Pablo Isaza Report

0

yours example:

let Ids = [data[0][1]].map(a => a.Id);

so, you have an array with 2 items

the first element with index = 0 will be number 3

the second element with index = 1 will be an array.

so:

console.log(data[0]) // 3
console.log(data[1]) // [...]

or we can use destructuring

const [firstNumber, array] = data;
//then
cosnt ids = array.map(i => i.Id)

UPDATE: if you are using typescript and getting this error:

getting this error map' does not exist on type 'number | { Id: number; name: string}[]'. Property 'map' does not exist on type 'number'.

You need to defined type of variable correcly.

we can use tuple types

var employee: [number, { Id: number; name: string}[]] = [1, [...]];
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!