Answers for "remove duplicate from array js"

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
11

javascript remove duplicate in arrays

// 1. filter()
function removeDuplicates(array) {
  return array.filter((a, b) => array.indexOf(a) === b)
};
// 2. forEach()
function removeDuplicates(array) {
  let x = {};
  array.forEach(function(i) {
    if(!x[i]) {
      x[i] = true
    }
  })
  return Object.keys(x)
};
// 3. Set
function removeDuplicates(array) {
  array.splice(0, array.length, ...(new Set(array)))
};
// 4. map()
function removeDuplicates(array) {
  let a = []
  array.map(x => 
    if(!a.includes(x) {
      a.push(x)
    })
  return a
};
/THIS SITE/ "https://dev.to/mshin1995/back-to-basics-removing-duplicates-from-an-array-55he#comments"
Posted by: Guest on April-27-2020
0

remove duplicate array es6

let a = [10,20,30,10,30];
let b = a.filter((item,index) => a.indexOf(item) === index);
console.log(b);
Posted by: Guest on November-23-2020
0

javascript to remove duplicates from an array

uniqueArray = a.filter(function(item, pos) {
    return a.indexOf(item) == pos;
})
Posted by: Guest on October-22-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
1

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

Code answers related to "remove duplicate from array js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language