-2

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();
jabaa
  • 5,844
  • 3
  • 9
  • 30

1 Answers1

-2

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

  • _"how to remove same elements from array and add **count to other objects** javascript?"_ Where do you count? Your code doesn't work with objects, only with primitives. – jabaa Mar 11 '22 at 21:12
  • i want to know how many element get removed – simple.nihad Mar 11 '22 at 21:23