Ganxiaozhe 2020-10-02 16:35:20
混合数组深度去重,源自项目 gQuery.js
function unique(arr,typ){
let j = {};
if( typ=='node' ){
return arr.filter(function(item, index, arr) {
return arr.indexOf(item, 0) === index;
});
}
arr.forEach(function(v){
let vtyp = typeof v,vv=v;
if(vtyp==='object'){v = JSON.stringify(v);}
j[v + '::' + vtyp] = vv;
});
return Object.keys(j).map(function(v){return j[v];});
}