1

I have a JavaScript object build as a list of dictionaries. example of a possible data set:

object =
[
{'name':'abc', 'type':'manual', 'some_id':'d23d', 'assigned_items':['this1']},
{'name':'hef', 'type':'manual', 'some_id':'3hhs', 'assigned_items':['this2, this3']},
{'name':'kuy', 'type':'manual', 'some_id':'k7fd', 'assigned_items':['this4']},
]

I am trying to get a list of all the assigned_items, which will sometimes be more than one. so the output I would like for this data set will be:

result = ['this1', 'this2', 'this3', 'this4']

I tried the answers explaind here, but it did not work

Javascript equivalent of Python's values() dictionary method

Zusman
  • 606
  • 1
  • 7
  • 31

1 Answers1

2

const input = [{'name':'abc', 'type':'manual', 'some_id':'d23d','assigned_items':['this1']},{'name':'hef', 'type':'manual', 'some_id':'3hhs', 'assigned_items':['this2', 'this3']},{'name':'kuy', 'type':'manual', 'some_id':'k7fd','assigned_items':['this4']},]

const res = input.flatMap(e => e.assigned_items)

console.log(res)
ulou
  • 5,542
  • 5
  • 37
  • 47