I am new in Javascript, I usually need to handle conversion between object and array, but how can I do it more elegant or clean in ES6/7 such as use Spread syntax
or lodash
..., rather than use for loop iteration.(since I don't like mutable stuff.)
I want to convert the below object:
{
book: {
1001: 'a',
1002: 'b',
1003: 'c'
},
game: {
1001: 'a'
}
}
to below array of object:
[
{
category: 'book',
item: [
{ id: 1001, name: 'a' },
{ id: 1002, name: 'b' },
{ id: 1003, name: 'c' }
]
},
{
category: 'game',
item: [
{ id: 1001, name: 'a' }
]
}
]