My question is simple. The array is claimed by a variable.
var array = [1,1,2,2,2,3,3,,4];
How can I get the new array like
array2 = [1,2,3,4]
My question is simple. The array is claimed by a variable.
var array = [1,1,2,2,2,3,3,,4];
How can I get the new array like
array2 = [1,2,3,4]
This might help (Unique values in an array). This answer is from above link
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
usage example:
var a = ['a', 1, 'a', 2, '1'];
var unique = a.filter( onlyUnique ); // returns ['a', 1, 2, '1']