I have the following data:
var data = {
"features": [
{
"properties": {
"route_id": 522,
"name": "the Mekong",
"tour_id": 538
}
},{
"properties": {
"route_id": 522,
"name": "Cambodia & the Mekong",
"tour_id": 545
}
},{
"properties": {
"route_id": 521,
"name": "Cambodia",
"tour_id": 537
}
}
]
}
Now, I want to group values that have similar "route_id"
into a nested array of objects; ultimately using lodash; so that the expected result will be as following:
var result = {
"features": [
{
"properties": [{
"route_id": 522,
"name": "the Mekong",
"tour_id": 538
},{
"route_id": 522,
"name": "Cambodia & the Mekong",
"tour_id": 545
}]
},{
"properties": {
"route_id": 521,
"name": "Cambodia",
"tour_id": 537
}
}
]
}
I tried using _.group
but I don't know how to get the nested array under one object. Also note that there will be other keys along with the "properties"
key but they're not relevant to the structure.