Populate array with values from another subarray

0

Lets say I have a json resul like this:

{
  "results": [{
      "id": 1, "name": "test1"
    },
    {
      "id": 2, "name": "test2",
      "tags": [{"name": "car"},{ "name": "love"}]
    },
    {
      "id": 3, "name": "test3",
      "tags": [{"name": "car"},{"name": "bike"},{"name": "motorcycle"}]
    }
  ]
}

I would like to mount a new array only with the unique tags, in this example would be car, love, bike, motorcycle.

Sometimes tags is null or empty…

Would have some way to do this without loops? jquery or underscore would fit this? could be done with pure javascript?

cheers

Link: Populate array with values from another subarray
Source: Stack Jquery

Share.

About Author

Leave A Reply