Skip to content Skip to sidebar Skip to footer

Is There A Function Like Array_unique() In Jquery?

I have a select where i can get some values as array like ['1','2','3'] On every change i run the following code to get a result of array which is connected to these values i get f

Solution 1:

try this:

functionunique(array){
  returnarray.filter(function(el, index, arr) {
      return index == arr.indexOf(el);
  });
}

working example:

const startingArray = [1, 2, 2, 3, 2, 3, 3, 3];

functionunique(array){
  return array.filter(function(el, index, arr) {
      return index == arr.indexOf(el);
  });
}

const uniqueArray = unique(startingArray);

console.log(uniqueArray);

Post a Comment for "Is There A Function Like Array_unique() In Jquery?"