Answers for "remove duplicates from array javascript es6"

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
9

javascript remove duplicates from array

unique = [...new Set(arr)];   // where arr contains duplicate elements
Posted by: Guest on July-03-2020
1

js delete duplicates from array

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

function removeDups(names) {
  let unique = {};
  names.forEach(function(i) {
    if(!unique[i]) {
      unique[i] = true;
    }
  });
  return Object.keys(unique);
}

removeDups(names); // // '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
0

remove duplicate array es6

let a = [10,20,30,10,30];
let b = [... new Set(a)];
console.log(b);
Posted by: Guest on November-23-2020
0

prevent duplicate entries in javascript array

if (array.indexOf(value) === -1) array.push(value);
Posted by: Guest on March-01-2021

Code answers related to "remove duplicates from array javascript es6"

Code answers related to "Javascript"

Browse Popular Code Answers by Language