标签:数组 bsp includes push ret unique rev for each
demo1: function uniqArray(array){
return [...new Set(array)]
}
demo2: function uniqArray(array){
var newArray = [];
array.forEach(value=>{
if(newArray.indexOf(value)=== -1){
newArray.push(value)
}
})
return newArray;
}
demo3: function uniqArray(array){
return array.filter(function(item, index, arr){
return array.indexOf(item, 0) === index;
}
}
demo4: function unique(array){
return array.reduce((prev,cur) => prev.includes(cur) ? prev : [...prev,cur],[]);
}
标签:数组 bsp includes push ret unique rev for each
原文地址:https://www.cnblogs.com/kmqz/p/13226013.html