Description: Because JavaScript1.5 adds some more useful methods to the array, such as foreach,
Filter,map,every,som,indexof, but is not available in browsers that do not support JavaScript1.5, so MooTools supports these methods by extending the array:
---------------------------------Array.js---------------------------------
A foreach method for 1.Array objects
Prototype: Array.prototype.forEach (Callback:function, Thisobject:object)
Function: An iterative operation of an array of two parameters, the first parameter callback is each iteration
The function that is executed, the second argument Thisobject optional, is the function to bind to the execution of the iteration
Object (that is, the object pointed to by this in the function callback)
Example:
Use a
var arr = [1,2,3,4,5,6];
arr.forEach(function(e){
alert(e);
});
Usage Two
var arr = [1,2,3,4,5,6];
var obj = "hello!";
arr.forEach(function(e){
alert(e+'--'+this); //这里的 this指后面的 obj 对象
},obj);
Usage Three
function Putelt (element, index, array) {
Element + ' <br> ');}
[2, 5, 9].foreach (Putelt);
Filter method for 2.Array objects
Prototype: Array.prototype.filter (Callback:function, Thisobject:object)
Function: An iterative algebra group, in which each element executes the callback method as a parameter, by the callback method as
Data filter, and finally returns an array of filtered
Example:
var result = [1,2,3,4,5].filter (function (e) {
return e > 3;
});
alert (result); The result is 4,5
3.Array object's Map method:
Prototype: Array.prototype.map (Callback:function, Thisobject:object)
Function: An iterative algebra group in which each element executes the callback method as a parameter by the callback method for each
element, and finally returns an array of processed
Example:
var result = [1,2,3,4,5].map (function (e) {
return e + ' px ';
});
alert (result); The result is 1px,2px,3px,4px,5px
The Every method for 4.Array objects:
Prototype: Array.prototype.every (Callback:function, Thisobject:object)
Function: Does it mean that every element in the array is processed by callback? If
Yes, returns true if one is not, then returns false
Example:
var result = [1,2,3,4,5].every (function (e) {
return e > 3;
});
alert (result); return False