Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
111
rated 0 times [  117] [ 6]  / answers: 1 / hits: 136925  / 10 Years ago, fri, november 7, 2014, 12:00:00

This is my Object



var data = {
a:{0: 1},
b:{1: 2},
c:{2: 3},
d:{3: 4}
};


This is the output that I expect



data = [ 
{0: 1},
{1: 2},
{2: 3},
{3: 4}
]

More From » lodash

 Answers
22

This works for me


var newArrayDataOfOjbect = Object.values(data)


In additional if you have key - value object try:


const objOfObjs = {
"one": {"id": 3},
"two": {"id": 4},
};

const arrayOfObj = Object.entries(objOfObjs).map((e) => ( { [e[0]]: e[1] } ));


will return:


[
{
"one": {
"id": 3
}
},
{
"two": {
"id": 4
}
}
]

[#68881] Wednesday, November 5, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mira

Total Points: 460
Total Questions: 108
Total Answers: 99

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
mira questions
;