I have an array of objects like this:
let list = [
{
\'items\': [
\'item 1\',
\'item 2\'
]
},
{
\'items\': [
\'item 3\'
]
You can flat the map()
result using Array.prototype.flatMap():
The
flatMap()
method first maps each element using a mapping function, then flattens the result into a new array.
let list = [
{
'items': [
'item 1',
'item 2'
]
},
{
'items': [
'item 3'
]
}
]
list = list.flatMap(i => i.items);
console.log(list);