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:
function unique(array){
return array.filter(function(el, index, arr) {
return index == arr.indexOf(el);
});
}
working example:
const startingArray = [1, 2, 2, 3, 2, 3, 3, 3];
function unique(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?"