remove duplicates from multidimensional array javascript code example

Example 1: javascript remove duplicate in two arrays

array1 = array1.filter(function(val) {
  return array2.indexOf(val) == -1;
});
// Or, with the availability of ES6:

array1 = array1.filter(val => !array2.includes(val));

Example 2: javascript remove duplicates from array

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

Example 3: javascript filter array remove duplicates

// Using the Set constructor and the spread syntax:

arrayWithOnlyUniques = [...new Set(arrayWithDuplicates)]

Example 4: javascript remove duplicates from array

var myArr = [1, 2, 2, 2, 3];
var mySet = new Set(myArr);
myArr = [...mySet];
console.log(myArr);
// 1, 2, 3

Example 5: remove duplicates from array javascript

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

Tags:

Css Example