Mithun
0
Q:

remove duplicate array es6

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

let unique = [...new Set(names)];
console.log(unique); // 'John', 'Paul', 'George', 'Ringo'
9
var data = [1, 2, 'Peter', 3, 3,'Peter', 2, 2, 1, 2, 3, 4, 4, 5, 4];
var unique = data.filter((v, i, a) => a.indexOf(v) === i);
3
const names = ['John', 'Paul', 'George', 'Ringo', 'John'];

let x = (names) => names.filter((v,i) => names.indexOf(v) === i)
x(names); // 'John', 'Paul', 'George', 'Ringo'
0
let a = [10,20,30,10,30];
let b = a.filter((item,index) => a.indexOf(item) === index);
console.log(b); 
0
function getNotUnique(array) {
    var map = new Map();
    array.forEach(a => map.set(a, (map.get(a) || 0) + 1));
    return array.filter(a => map.get(a) > 1);
}

console.log(getNotUnique([1, 2, 2, 4, 4])); //[2, 2, 4, 4]
console.log(getNotUnique([1, 2, 3] )); //[]
0
let a = [10,20,30,10,30];
let b = [... new Set(a)];
console.log(b);
0
let a = [10,20,30,50,30];
let b = a.reduce((unique,item) => unique.includes(item) ? unique: [... unique, item] ,[]); 
console.log(b);
0

Tags

New to Communities?

Join the community