I build this array:
const array = [
{
title: 'something',
list: ['a', 'b', 'c', 'd']
},
{
title: 'dog',
list: ['aa']
},
{
title: 'cat',
list: ['aaa', 'b', 'cccc']
},
{
title: 'apple',
list: [],
}
]
I would like an array containing all the values in the other arrays, so:
const res = ['a', 'b', 'c', 'd', 'aa', 'aaa', 'b', 'cccc']
I can I do that? I can use concat but how?
array.reduce((result,item)=>result.concat(item.list),[])listto an accumulator array.