Here is an array of JSON objects that has array values that I want to group by (pull unique):
let myArray = [
{
"_id": "1",
"subdata": [
{
"subid": "11",
"name": "A"
},
{
"subid": "12",
"name": "B"
}
]
},
{
"_id": "2",
"subdata": [
{
"subid": "12",
"name": "B"
},
{
"subid": "33",
"name": "E"
}
]
}
]
Finally I need to get:
[
{
"subid": "11",
"name": "A"
},
{
"subid": "12",
"name": "B"
},
{
"subid": "33",
"name": "E"
}
]
I've tried lodash with no success:
let newArray = lodash.uniqBy(lodash.concat(myArray, 'subdata.subid'), '_id');
Of course I can scan each array element one by one but thought there is easy way to do it with lodash