I am looking for a way to transform an object into an array of objects, and remove the first unique key.
How can I make this:
JavaScript
x
2
1
{f56hdhgf54: {name: 'Sam', age: 34}, h65fg9f7d: {name: 'John', age: 42}}
2
into this:
JavaScript
1
2
1
[{name: 'Sam', age: 34}, {name: 'John', age: 42}]
2
so I can .map
through it like this:
JavaScript
1
4
1
result.map((person) => {
2
console.log(person.name, person.age)
3
})
4
Advertisement
Answer
You can use Object.keys()
to get array of keys and then map()
to change keys to values or in this case objects.
JavaScript
1
7
1
var obj = {f56hdhgf54: {name: 'Sam', age: 34}, h65fg9f7d: {name: 'John', age: 42}}
2
3
var result = Object.keys(obj).map(function(e) {
4
return obj[e];
5
});
6
7
console.log(result);