阅读背景:

js 去重(字符串、数组对象)

来源:互联网 

1.去重字符串

var v = "1343、rere、1343、rerd";//需要去重的字符串
var arr = v.split('、');//["1343", "rere", "1343", "rerd"]
Array.prototype.unique = function(){
	var res = [];
	var json = {};
	for(var i = 0; i < this.length;i++){
		if(!json[this[i]]){
			res.push(this[i]);
			json[this[i]] = 1;
		}
	}
	console.log(json);//{1343: 1, rere: 1, rerd: 1}
	return res;
}
console.log(arr.unique());//["1343", "rere", "rerd"]
var qcsz = arr.unique().join("、");
console.log(qcsz);//1343、rere、rerd
var v = "1343、rere、1343、rerd";//需



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: