Find your content:

Search form

You are here

best way to check duplicates in javascript object

 
Share

Use object instead of array so that runtime will be O(1) in the lookup.

function duplicate(data){
  let duplicates = {};
  let result = [];
  data.map( function(elem) {
   if(!duplicates[elem]){
      duplicates[elem] = true;
      result.push(elem);
   }
 }
 return result;
}

My Block Status

My Block Content