remove duplicates from two 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: remove duplicates from array javascript
[...new Set(array)]