JAVASCRIPT
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));
remove duplicates from array js
const myArray = [2,5,6,2,2,4,5,3,3];
const uniqueArray = [...new Set(myArray)];
console.log(uniqueArray);
javascript to remove duplicates from an array
uniqueArray = a.filter(function(item, pos) {
return a.indexOf(item) == pos;
})
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
javascript remove duplicates from array
unique = [...new Set(arr)]; // where arr contains duplicate elements
javascript remove duplicates from array
// for TypeScript and JavaScript
const initialArray = ['a', 'a', 'b',]
finalArray = Array.from(new Set(initialArray)); // a, b
javascript to remove duplicates from an array
uniqueArray = a.filter(function(item, pos) {
return a.indexOf(item) == pos;
})
remove duplicates from array javascript
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
// usage example:
var a = ['a', 1, 'a', 2, '1'];
var unique = a.filter(onlyUnique);
console.log(unique); // ['a', 1, 2, '1']
remove duplicates multidimensional array javascript
var arr = [[7,3], [7,3], [3,8], [7,3], [7,3], [1,2]];
arr.map(JSON.stringify).reverse().filter((e, i, a) => a.indexOf(e, i+1) === -1).reverse().map(JSON.parse) // [[7,3], [3,8], [1,2]]
compare two arrays and remove duplicates javascript
array1 = array1.filter(function(val) {
return array2.indexOf(val) == -1;
});
remove duplicates from array javascript
remove duplicates from array javascript
arr.filter((v,i,a)=>a.findIndex(t=>(t.place === v.place && t.name===v.name))===i)
javascript remove duplicates from array
let chars = ['A', 'B', 'A', 'C', 'B'];
let uniqueChars = [...new Set(chars)];
console.log(uniqueChars);
Code language: JavaScript (javascript)