1.判断数组中是否包含某字符
Array.prototype.contains =
function
(v){
var
b =
false
;
for
(
var
i=0;i<
this
.length;i++){
if
(
this
[i] == v){
b =
true
;
break
;
}
}
return
b;
};
2.遍历JSON字符串
http://www.jb51.net/article/44441.htm
3.js中在数组中添加或删除元素
http://www.cnblogs.com/yuzhongwusan/archive/2008/12/15/1355378.html
4.js中数组中去重
http://www.jb51.net/article/54176.htm
5.json对象去重
Array.prototype.unique= function () {
var res = [this[0]];
for (var i = 1; i < this.length; i++) {
var repeat = false;
for (var j = 0; j < res.length; j++) {
if (this[i].deptID == res[j].deptID) {
repeat = true;
break;
}
}
if (!repeat) {
res.push(this[i]);
}
}
return res;
}
var res = [this[0]];
for (var i = 1; i < this.length; i++) {
var repeat = false;
for (var j = 0; j < res.length; j++) {
if (this[i].deptID == res[j].deptID) {
repeat = true;
break;
}
}
if (!repeat) {
res.push(this[i]);
}
}
return res;
}