An iterative approach to JavaScript array arrays

Source: Internet
Author: User
Tags javascript array



Methods for JavaScript iterations
Filter () uses the specified function to determine whether to return an item contained in an array
var num = [1,2,3,4,5,6,12];


Num.filter (function (item, index, array) {
Return (item > 2); [3, 4, 5, 6, 12]
});


Map () returns an array in which each item is the result of running an incoming parameter on the corresponding item in the original array


var num = [1,2,3,4,5,4,3,2,1];
Num.map (function (item, index, array) {
Return (item * 2); [2, 4, 6, 8, 10, 8, 6, 4, 2]
});


Every () some (), query whether an item in the array conforms to a condition every () must pass in the argument each return true, the result is the True;some () method
As long as one is true, the result is true


var num = [1,2,3,4,5,4,3,2,1];
Num.every (function (item, index, array) {
Return (item > 2); False
});


Num.some (function (item, index, array) {
Return (item > 2); True
})


ForEach () Each entry parameter of the array, no return value
var num = [1,2,3,4,5,4,3,2,1];
Num.foreach (function (item, index, array) {
return item;
})

An iterative approach to JavaScript array arrays

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.