I have an array of grouped objects, but I'm unable to iterate through and achieve the desired result.
[ 000000010: [
{
"userId" : "000000010",
"played" : 10,
"lost" : 5,
"date" :"2019-04-01T00:00:00.000Z"
},
{
"userId" : "000000010",
"played": 15,
"lost" : 0,
"date" :"2019-04-02T00:00:00.000Z"
},
],
000000020: [
{
"userId" : "000000020",
"played": 11,
"lost" : 4,
"date" :"2019-04-01T00:00:00.000Z"
},
{
"userId" : "000000020",
"played": 15,
"lost" : 0,
"date" :"2019-04-02T00:00:00.000Z"
},
]
]
I want to eliminate all possible duplicates and group all similar objects as follows
{
"userId" : "000000010",
"played": 30,
"lost" : 5,
},
{
"userId" : "000000020",
"played": 26,
"lost" : 6,
},
I have tried
Object.entries()
but it returned
[obeject: object]
I have also tried
const allResults = {}
Object.keys(result).forEach(function(key) {
let chats = result[key].chats;
allResults[chats] = allResults[chats] ? allResults[chats] + 1 : 1;
});
But I get undefined
{foo: 'bar'} === {foo: 'bar'}will evaluate to false (try running that in console to see. it's doable however. for a little more info on that and a possible appraoch, check out: stackoverflow.com/questions/11704971/…., though theuserID` is same as the Entry ID itself, both objects have unique values. so how does the code decide which is entry is to be deleted?jsondata. Please correct the missingcolonsagainst few keys such asplayed.00000010had at least 7 entries. With the help of the answer by metakungfu here stackoverflow.com/questions/40774697/… I was able to group them into the same IDs.keyvalue ofdate? Please look at the Answer given below.