I have been toying with the best way to go about doing this and have found some options but not one that preserves the format I am trying to keep for the array/object.
The overview is I have an array that gets random objects pushed into it and there can be duplicates of the same object, but I want to change it so there is only 1 of each object and instead, having a count property for each object.
An example of what I am working with and what I am aiming to have.
arr = [
{ Name: Item1, Value: 20 },
{ Name: Item2, Value: 20 },
{ Name: Item1, Value: 20 }
];
result = [
{ Name: Item1, Value: 20, Count: 2 },
{ Name: Item2, Value: 20, Count: 1 }
];
As a side note, I am wondering if it better to do this after the array is filled or if it is better to do this while pushing the objects into the array?
NameandValue, or only byName?