Answers for "js create array without duplicates"

50

js delete duplicates from array

const names = ['John', 'Paul', 'George', 'Ringo', 'John'];

let unique = [...new Set(names)];
console.log(unique); // 'John', 'Paul', 'George', 'Ringo'
Posted by: Guest on March-11-2020
0

remove duplicates from array javascript

function onlyUnique(value, index, self) {
  return self.indexOf(value) === index;
}

// usage example:
var a = ['a', 1, 'a', 2, '1'];
var unique = a.filter(onlyUnique);

console.log(unique); // ['a', 1, 2, '1']
Posted by: Guest on March-16-2021

Code answers related to "js create array without duplicates"

Code answers related to "Javascript"

Browse Popular Code Answers by Language