Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is the JavaScript Object: 

var dataObject = {

   object1: {id: 1, name: "Fred"}, 

   object2: {id: 2, name: "Wilma"}, 

   object3: {id: 3, name: "Pebbles"}

}

Can anyone tell me how to efficiently extract inner objects into an array, without having to maintain handles on the object[n] IDs? 

var dataArray = [

    {id: 1, name: "Fred"}, 

    {id: 2, name: "Wilma"}, 

    {id: 3, name: "Pebbles"}]

1 Answer

0 votes
by (19.7k points)

You can use the code below:

var dataArray = [];

for(var o in dataObject) {

    dataArray.push(dataObject[o]);

}

Interested in Java? Check out this Java Certification by Intellipaat. 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...