I'm trying to bring out object from an array which inside an array
from this
[[{…}],[{…}],[{…}],[{…}],[{…}],[{…}]]
into this
[{…},{…},{…},{…},{…},{…}]
I'm trying to bring out object from an array which inside an array
from this
[[{…}],[{…}],[{…}],[{…}],[{…}],[{…}]]
into this
[{…},{…},{…},{…},{…},{…}]
Use Array.flat()
:
const arr = [[{a:1}],[{a:2}],[{a:3}]];
const output = arr.flat();
console.log(output);
Simply flatten
the array:
const arr = [[{a:1}],[{a:2}],[{a:3}]];
const flattened1 = [].concat(...arr); // With destructuring
const flattened2 = arr.flat(); // with Array.flat();
console.log(flattened1);
console.log(flattened2);