'Is there a function to find how many of a duplicate there are in an array with objects, then remove all the duplicates? [duplicate]
let array = [{
fruit: "banana",
number: 1
},
{
fruit: "banana",
number: 2
},
{
fruit: "rambutan",
number: 1
},
{
fruit: "rambutan",
number: 1
}
]
I would first like to find the total number of one fruit, then remove the duplicates, so that the array will become:
[{
fruit: "banana",
number: 3
},
{
fruit: "rambutan",
number: 2
}
]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
