Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[30,33,34]

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

>Solution :

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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading