Reputation: 13
Imagine you have this :
[[{id: 1}], [{id: 2}]]
Is posible to convert the previous array in something like this? :
[{id:1}, {id:2}]
Upvotes: 1
Views: 50
Reputation: 3091
One way is:
console.log([[{id: 1}], [{id: 2}]].map(arr => arr[0]))
Another way is Array.prototype.flat()
:
const arr1 = [[{id: 1}], [{id: 2}]]
console.log(arr1.flat())
Upvotes: 2
Reputation: 8718
You can simply use Array.prototype.flat for that:
console.log([
[{
id: 1
}],
[{
id: 2
}]
].flat());
Upvotes: 3