const arr = [1, 2, 1, 4, 5, 6, 7, 4];
const newArr = arr.filter((currentVlaue, index, arr) => {
return index === arr.indexOf(currentVlaue);
})
function unique(arr) {
var res = [arr[0]];
for (var i = 1; i < arr.length; i++) {
var repeat = false;
for (var j = 0; j < res.length; j++) {
if (arr[i] == res[j]) {
repeat = true;
break;
}
}
if (!repeat) {
res.push(arr[i]);
}
}
return res;
}
原文:https://www.cnblogs.com/Yancyzheng/p/10648162.html