var n = [1,2,2,3,4,5,6,2,3]; var set = new Set(); var duplicates = new Set(); for(i=0;i < n.length;++i){ if(set.has(n[i])){ duplicates.add(n[i]); } else{set.add(n[i]);} }console.log(duplicates)