duplicate remove javascript 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: callback without duplicates javascript

function myFunction(myArray, callBack){

 var unique = myArray.filter(function(item, pos) {
   //validates whether the first occurrence of current item in array
   // equals the current position of the item (only return those items) 
   return myArray.indexOf(item) == pos;
 });

 //wrap your result and pass to callBack function 
 callBack(unique);

}