filter repeated numbers from 2 arrays javascript code example
Example 1: javascript remove duplicate in arrays
function removeDuplicates(array) {
return array.filter((a, b) => array.indexOf(a) === b)
};
function removeDuplicates(array) {
let x = {};
array.forEach(function(i) {
if(!x[i]) {
x[i] = true
}
})
return Object.keys(x)
};
function removeDuplicates(array) {
array.splice(0, array.length, ...(new Set(array)))
};
function removeDuplicates(array) {
let a = []
array.map(x =>
if(!a.includes(x) {
a.push(x)
})
return a
};
/THIS SITE/ "https://dev.to/mshin1995/back-to-basics-removing-duplicates-from-an-array-55he#comments"
Example 2: javascript remove duplicate in two arrays
array1 = array1.filter(function(val) {
return array2.indexOf(val) == -1;
});
array1 = array1.filter(val => !array2.includes(val));
Example 3: javascript create array with repeated values
Array(5).fill(2)