How to remove duplicated values in this object array in javascript?
0: {d: “2021/01/19”, color: “#009988"}
1: {d: “2021/01/19”, color: “#CC3311"}
2: {d: “2021/01/19”, color: “#009988"}
3: {d: “2021/01/19”, color: “#009988"}
4: {d: “2021/01/20”, color: “#009988"}
5: {d: “2021/01/22”, color: “#009988"}
I want to filter this object array like this:
0: {d: “2021/01/19”, color: “#009988"}
1: {d: “2021/01/19”, color: “#CC3311"}
2: {d: “2021/01/20”, color: “#009988"}
3: {d: “2021/01/22”, color: “#009988"}
I have done this way, but the result was not what I wanted.
for (let i = 0; i < array.length-1; i++) {
if (arr[i].d === array[i+1].d) {
if (array[i].color === array[i+1].color) {
array.splice(i, 1);
i--;
}
}
}