Answers for "how to filter duplicate items in an array in javascript"

95

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
1

javascript remove duplicates from array

// for TypeScript and JavaScript
const initialArray = ['a', 'a', 'b',]
finalArray = Array.from(new Set(initialArray)); // a, b
Posted by: Guest on April-17-2021
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 "how to filter duplicate items in an array in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language