(1)clean
var arr = [1,2,null,3,''];
alert(Ext.Array.clean(arr));
//clean的对象:(value === null) || (value === undefined) || (!allowEmptyString ? value === '' : false) || (Ext.isArray(value) && value.length === 0)
//结果为1,2,3
(2)difference
//difference
var arr1 = [1,2,3];
var arr2 = [2,5,6];
alert(Ext.Array.difference(arr1,arr2));
//结果为:1,3
(3)each
//each
var arr = [1,2,3,4];
Ext.Array.each(arr, function(item){
if(item == 4){
return false ;
}
alert(item);
//当函数内部返回false的时候会停止迭代
});
//结果:依次弹出对话框,分别显示1 2 3,不显示4
(4)erase
//erase
var arr = [1,2,3,4,5];
alert(Ext.Array.erase(arr , 2 , 2));//数组从0開始。从下标为2的位置開始(包括)。删除两个元素
//结果:1,2,3
(5)every
//every
var arr = [1,2,5,6,9,10];
var flag = Ext.Array.every(arr, function(item){
if(item >=7){
return false ;
}else {
return true;
}
});
alert(flag);
//结果:false
(6)filter
//filter
var arr = [1,2,3,4,10,18,23];
var newarr = Ext.Array.filter(arr,function(item){
if(item > 10){
return false ;
} else {
return true ;
}
});
alert(newarr);
//结果:1,2,3,4,10
(7)include
//include
var arr = [1,2,3,4];
Ext.Array.include(arr , 2);
alert(arr);
//结果:1,2,3,4
(8)unique
//unqiue
var arr = [1,2,3,4,5,5,4,3,2,1,1,21,23,3,3,4];
alert(Ext.Array.unique(arr));
// 利用js对象的特性去掉数组的反复项 obj的key是不能反复的
var obj = {};
for(var i = 0 , len = arr.length ; i <len ; i++){
obj[arr[i]] = true ;//去掉数组的反复项了
}
//alert(Ext.encode(obj));
var uniquearr = [];
for(var i in obj){
if(obj.hasOwnProperty(i)){
uniquearr.push(i);
}
}
alert(uniquearr);
//结果:1,2,3,4,5,21,23