Answers for "use set to remove duplicates in javascript"

1

use set to remove duplicates in javascript

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

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

use set to remove duplicates in javascript

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

let x = (names) => names.filter((v,i) => names.indexOf(v) === i)
x(names); // 'John', 'Paul', 'George', 'Ringo'
Posted by: Guest on February-14-2020
2

remove duplicates from array javascript

arr.filter((v,i,a)=>a.findIndex(t=>(t.place === v.place && t.name===v.name))===i)
Posted by: Guest on September-10-2020
0

use set to remove duplicates in javascript

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 September-18-2020

Code answers related to "use set to remove duplicates in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language