Js remove same elements from array

Code examples

36
0

js delete duplicates from array

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

let unique = [...new Set(names)];
console.log(unique); // 'John', 'Paul', 'George', 'Ringo'
2
0

javascript remove duplicate strings from array

//ES6
let uniqueArray = [...new Set(arrayWithDuplicates)];

//Alternative
function removeArrayDuplicates(arrayWithDuplicates) {
    let seen = {};
    let uniqueArray = [];
    let len = arrayWithDuplicates.length;
    let j = 0;
    for(let i = 0; i < len; i++) {
         let item = arrayWithDuplicates[i];
         if(seen[item] !== 1) {
               seen[item] = 1;
               uniqueArray[j++] = item;
         }
    }
    return uniqueArray;
}
2
0

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 ]

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................