1
Next, I’m a designer and I’m slowly learning javascript. One of the things I have the most difficulties with is objects and arrays, so I’m focusing more on that now. I have an array with 4 objects as the following code.
var players = [{
name: "Batman",
id: "1",
points: 10
},
{
name: "Superman",
id: "2",
points: 10
},
{
name: "Batman",
id: "1",
points: 10
},
{
name: "Superman",
id: "2",
points: 5
}
];
What I need: return objects with the same ids and points summed, resulting in 2 objects.
What is the logic I use to solve this problem? How to join objects with the same id and add the points of each one? I was able to do it with only 1 object, but I was comparing it with the id. If I had a much larger array, it would be almost impossible to keep comparing one by one. I want to understand the logic applied in this context.