Filter through an array and remove empty item as defined inExt.isEmpty
过滤掉数组中的项该项如果为空(Ext.isEmpty==true)则过滤掉
See filter
Parameters
- array :Array
Returns
- Array
results
例子:
var arr = [1,4,2,12,,13];
alert(arr.length); //{6个}
var arr1 = Ext.Array.clean(arr);
alert(arr1.length);//(5个)
difference( Array arrayA, Array arrayB ) : Array
Perform a set difference A-B by subtracting all items in array B from array A.
对比两个数组A、B,返回A数组中的项在B数组中没有出现过的。
Parameters
Returns
- Array
difference
例子:
Ext.onReady(function(){
// Ext.MessageBox.alert("Hello","Hello Word!!");
var arr1 = [1,4,2,12,13];
var arr2 = [1,4,2,12,13,17];
var resultArra = Ext.Array.difference(arr1,arr2);
alert(resultArra.length);(返回0)
});
each( Array/NodeList/Object iterable, Function fn, [Object scope], [Boolean reverse] ) : Boolean
Iterates an array or an iterable value and invoke the given callback function for each item.
遍历一个数组或是迭代一个值(这里迭代不准确,见例子),调用函数来循环每项的
var countries = ['Vietnam', 'Singapore', 'United States', 'Russia'];
Ext.Array.each(countries, function(name, index, countriesItSelf) {
console.log(name);
});
var sum = function() {
var sum = 0;
Ext.Array.each(arguments, function(value) {
sum += value;
});
return sum;
};
sum(1, 2, 3); // returns 6
The iteration can be stopped by returning false in the function callback.
在回调函数中通过return false来结束对conuntries的迭代
Ext.Array.each(countries, function(name, index, countriesItSelf) {
if (name === 'Singapore') {
return false; // break here
}
});
Ext.each is alias for Ext.Array.each
Parameters
- iterable : Array/NodeList/Object
The value to be iterated. If thisargument is not iterable, the callback function is called once.
- fn : Function
The callback function. If it returns false, the iteration stops and this method returnsthe current
index
.Parameters
- item : Object
The item at the current
index
in the passedarray
- index : Number
The current
index
within thearray
- allItems : Array
The
array
itself which was passed as the first argument
Returns
- Boolean
Return false to stop iteration.
- item : Object
- scope : Object (optional)
The scope (
this
reference) in which the specified function is executed. - reverse : Boolean (optional)
Reverse the iteration order (loop from the end to the beginning)Defaults false
Returns
- Boolean
See description for the
fn
parameter.