remove duplicate array of array js code example
Example 1: js delete duplicates from array
const names = ['John', 'Paul', 'George', 'Ringo', 'John'];
let unique = [...new Set(names)];
console.log(unique); // 'John', 'Paul', 'George', 'Ringo'
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)]
Example 4: how to remove duplicate values in array javascript
var car = ["Saab","Volvo","BMW","Saab","BMW",];
var cars = [...new Set(car)]
document.getElementById("demo").innerHTML = cars;
Example 5: js delete duplicates from array
const names = ['John', 'Paul', 'George', 'Ringo', 'John'];
function removeDups(names) {
let unique = {};
names.forEach(function(i) {
if(!unique[i]) {
unique[i] = true;
}
});
return Object.keys(unique);
}
removeDups(names); // // 'John', 'Paul', 'George', 'Ringo'
Example 6: remove duplicate array es6
let a = [10,20,30,10,30];
let b = a.filter((item,index) => a.indexOf(item) === index);
console.log(b);