I have an array collecting objects like
myArray = [
{ lid_id: "1_1", et: "car", ty: "STS", dc: null, c: null, cp: null, im: false},
{ lid_id: "1_1", et: "car", ty: "STS", dc: 7, c: 11333, cp: 60, im: true},
{ lid_id: "1_2", et: "car", ty: "STC", dc: null, c: null, cp: null, im: false},
{ lid_id: "10_14473", et: "truck", ty: null, dc: 7, c: 14869, cp: 40, im: true}
]
I want to build new objects and colllect dc, c, cp and im keys if lid_id has the same value. For example following object which has key-value "lid_id":"1_1" collects the elements under ce. How can I collect these elements if lid_id is same?
myArray.forEach(function(data){
"body": { "lid_id": "1_1",
"et": "car",
"ty": "STS",
"ce": [
{
"dc": null,
"c": null,
"cp": null,
"im": false
},
{
"dc": 7,
"c": 11333,
"cp": 60,
"im": true
}
]
},
"body": { "lid_id": "1_2",
"et": "car",
"ty": "STC",
"ce": [
{
"dc": null,
"c": null,
"cp": null,
"im": false
}
]
},
"body": { "lid_id": "10_14473",
...............
}
})
"body": { ... }"entries on the same level.