Reduce multiple arrays in to one big array
Reduce multiple arrays in to one big array
by lshettyl
JavaScript
// An array of objects
var items = [{
name: 'x',
hobbies: ['a', 'b', 'c']
}, {
name: 'y',
hobbies: ['k', 'l', 'm']
}, {
name: 'y',
hobbies: ['x', 'x2', 'x3']
}];
let allHobbies = () => items.reduce((initial, curr) => [...initial, ...curr.hobbies], []);
console.log(allHobbies())