I have an array of objects like this:
let list = [
{
\'items\': [
\'item 1\',
\'item 2\'
]
},
{
\'items\': [
\'item 3\'
]
you can use the Array.reduce method and follow the docs here
{
let list = [
{
'items': [
'item 1',
'item 2'
]
},
{
'items': [
'item 3'
]
}
];
/**
* @parameter {Array} arg
*/
function splat (arg) {
return arg.reduce((total, { items }) => [...total, ...items], []);
}
console.log(splat(list));
}
You could also play with recursive function to make a more generic function that accepts array of nested objects.