3
I have the following array:
[
{
"value":"ETH",
"label":"ETH"
},
{
"value":"LTC",
"label":"LTC"
},
{
"value":"ETH",
"label":"ETH"
}
]
As you can see, there are duplicate values. What is the best way to remove them?
I’ve tried to do these two ways, but to no avail:
let values = [
{
"value":"ETH",
"label":"ETH"
},
{
"value":"LTC",
"label":"LTC"
},
{
"value":"ETH",
"label":"ETH"
}
]
console.log(values.filter((elem, index, self) => index === self.indexOf(elem)))
console.log([... new Set(values)])
I don’t understand why the set didn’t work, since it tries to create a single value list.
give a look here https://answall.com/questions/16483/remover-elements-repeating-dentro-de-um-vetor-em-javascript
– Wees Smith
@Weessmith The answer to this question (as it indicates) does not work for an object vector.
– Francisco