var routePlan = [
{
"id" : 1,
"farmerName" : "Farmer1",
"farmerId" : 1
},
{
"id" : 2,
"farmerName" : "Farmer2",
"farmerId" : 2
},
{
"id" : 1,
"farmerName" : "Farmer3",
"farmerId" : 3
}
];
I'm looking to consolidate objects with the same id into a single combined object using either javascript or angularjs.
var routePlan = [
{
"id" : 1,
"farmers" : [
{
"farmerName" : "Farmer1",
"farmerId" : 1
},
{
"farmerName" : "Farmer3",
"farmerId" : 3
}
]
},
{
"id" : 2,
"farmerName" : "Farmer3",
"farmerId" : 2
}
];
I've searched online for examples, but haven't found one that fits my specific needs. Any help would be appreciated!