Optimized pulling items out of arrays in nested objects 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 =&gt; data.items.forEach(item =&gt; result.push(item)))

  return _.uniq(result)
}


lodash is allowed

Any suggestion is more than welcome
Although at the time of writing, flatMap is not in every browser (according to MDN not in Edge and Samsung Internet);

data.flatMap(obj =&gt; obj.items).filter((e, i, ary) =&gt; ary.indexOf(e) == i)


Although, you could check the uniqueness from the result array in your code, and push only if not in there, to save one loop over the array.

Another option would be a reducer like

uniqItems = (acc, {items}) =&gt; acc.concat(items.filter(item =&gt; acc.indexOf(item) &lt; 0))


to data.reduce(uniqItems, []).