Delete duplicates in an array
- One of the function use the native method of JS ES6
- Is there a better method (compatibility and performance) ?
Note: filter the undefined element in the array
English is weak and maybe described as inaccurate. >﹏<
Thanks
function delRepeatArray1(arr) {
console.time();
var result = Array.from(new Set(arr));
console.timeEnd();
return result;
}
function delRepeatArray2(arr) {
console.time();
var result = arr.filter(function (em, index, arr) {
return arr.indexOf(em) === index;
});
console.timeEnd();
return result;
}
var arr = ["undefined", "200", 0, -0, 200, undefined, undefined, null, true, null, "true", false, 0, true, 200, false],
result1 = delRepeatArray1(arr),
result2 = delRepeatArray2(arr);
console.log(result1);
console.log(result2);