I found a couple of similar questions, but they were mostly outdated. Here's the problem: create a flat array from the values in several arrays contained in several nested objects.
const data = [
{ id: 1, items: ['one', 'two', 'three'] },
{ id: 2, items: ['two', 'one', 'four'] },
]
Expected result const result = ['one', 'two', 'three', 'four']
My current solution:
function() {
const result = []
data.forEach(item => data.items.forEach(item => result.push(item)))
return _.uniq(result)
}
lodash is allowed
Any suggestion is more than welcome