MooTools framework "Three"-array: Method Complete Analysis

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.