Answers for "remove duplicates froma rray js"

95

js delete duplicates from array

const names = ['John', 'Paul', 'George', 'Ringo', 'John'];

let unique = [...new Set(names)];
console.log(unique); // 'John', 'Paul', 'George', 'Ringo'
Posted by: Guest on March-11-2020
2

Remove duplication from array in javascript

const names = ["Alvi", "Arham", "Talha", "Safi", "Sameer", "Nazmi", "labli", "Arham", "Talha", "Labiba", "Tabassum", "Adiba"];
function removeDuplication(names) {
    const unique = [];
    for (element of names) {
        if (unique.indexOf(element) == -1) {
            unique.push(element)
        }
    }
    return unique;
}
console.log(removeDuplication(names));
//Output:
/* [
    'Alvi',
    'Arham',  'Talha',
    'Safi',   'Sameer',
    'Nazmi',  'labli',
    'Labiba', 'Tabassum',
    'Adiba'
] */
Posted by: Guest on December-17-2021
0

Remove Array Duplicate

const removeDuplicates = (arr) => [...new Set(arr)];

console.log(removeDuplicates([1, 2, 3, 3, 4, 4, 5, 5, 6]));
// Result: [ 1, 2, 3, 4, 5, 6 ]
Posted by: Guest on January-07-2022
-1

remove duplicate array es6

let a = [10,20,30,50,30];
let b = a.reduce((unique,item) => unique.includes(item) ? unique: [... unique, item] ,[]); 
console.log(b);
Posted by: Guest on November-23-2020

Code answers related to "remove duplicates froma rray js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language