I have 1 object (it came from localstroage). But there are some dublicates. how can i remove it from easy way?
"mainchart" is my array object.
function check() {
for (let i1 = 0; i1 < mainchart.length; i1++) {
for (let i2 = 0; i2 < mainchart.length; i2++) {
if (mainchart[i1].id === mainchart[i2].id) {
console.log(mainchart[i1] , mainchart[i2]);
}
}
}
}
check();
An easy way to remove duplicate values from an array is converting the array in to a set (collection of unique values), putting the values of the set in a new array:
let array1 = ["a", "b", true, 3, 67, true, "a"];
let array2 = [...new Set(array1)];
console.log(array2); // [ 'a', 'b', true, 3, 67 ]
Hope it can help you 🦄