Open alanhe421 opened 6 years ago
var ttt = [1, 1, 1, 1, 14, 5];
Array.prototype.distinct = function () {
var newArr = [];
this.forEach(it => {
if (newArr.indexOf(it) < 0) {
newArr.push(it);
}
});
return newArr;
};
ttt = ttt.distinct();
console.log(ttt);
let aaa=[1,3,2,4,5,5,6,1];
const bbb=new Set(aaa);
aaa=Array.from(bbb);
console.log(aaa);
相关文档:Set object-MDN
ECMA中所有函数的参数都是按值传递的。