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];});
}

评论

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.123.4. UTC+08:00, 2024-04-18 00:31
浙ICP备14020137号-1 $访客地图$