how to delete duplicates in array javascript code example

Example 1: javascript remove duplicates from array

unique = [...new Set(arr)];   // where arr contains duplicate elements

Example 2: how to remove duplicates in array in javascript

const numbers = [1 , 21, 21, 34 ,12 ,34 ,12];
const removeRepeatNumbers = array => [... new Set(array)]
removeRepeatNumbers(numbers) // [ 1, 21, 34, 12 ]

Example 3: remove duplicates from array javascript

arr.filter((v,i,a)=>a.findIndex(t=>(t.place === v.place && t.name===v.name))===i)

Example 4: js delete duplicates from array

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

let x = (names) => names.filter((v,i) => names.indexOf(v) === i)
x(names); // 'John', 'Paul', 'George', 'Ringo'

Tags:

Css Example