2.1 remove duplicates 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: 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 ]