reduce remove duplicates code example

Example 1: 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;
}

Example 2: deduplicate array javascript

function uniq(a) {
   return Array.from(new Set(a));
}