An example analysis of an iterative method for array arrays in JavaScript

Source: Internet
Author: User
Tags foreach arrays

This article mainly introduces the iterative method of array arrays in JavaScript, and analyses the definition and use techniques of array arrays, and needs friends to refer to the following

The examples in this article describe the JavaScript iteration approach. Share to everyone for your reference. The implementation methods are as follows:

The code is as follows:

Filter () Determines whether an item contained in an array is returned by using the specified function.

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 runs the result of an incoming argument on a 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 () to query whether an item in the array meets a condition every () the arguments that must be passed in each return true, and 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 () Incoming arguments for each entry in the array, no return value

var num = [1,2,3,4,5,4,3,2,1];

Num.foreach (function (item, index, array) {

return item;

})

I hope this article will help you with your JavaScript programming.

Related Article

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.