Is there a way to eliminate duplicate values in an object array using 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 am looking to filter this object array as follows:
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 attempted to achieve this by implementing the given code, but it did not produce the expected result.
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--;
}
}
}