JS array of higher order functions commonly used methods foreach, map, reduce

Source: Internet
Author: User

The 1.forEach method is used to invoke each element of an array and pass the element to a callback function.

Array.foreach (function (Currentvalue,index,arr), thisvalue);

1.currentValue must be. The current element.
2.index is optional. The index value of the current element.
3.arr is optional. The array object that corresponds to the current element
4.thisValue is optional. The value passed to the function is generally used with this value, and if this argument is null, "undefined" is passed to the "this" value

The 2.map () method returns a new array in which the elements of the array call the function-processed values for the original array element.

Array.map (function (Currentvalue,index,arr), Thisvalue)

1.currentValue must be, the value of the current element
2.index is optional. The index value of the current element
3.arr is optional. The array object to which the current element is subordinate
4.thisValue is optional. object is used as the execution callback. Passed to the function as the "this" value. If this parameter is empty, "undefined" is passed to the "this" value

3.thereduce method receives a function as an accumulator, and each value in the array begins to shrink and is finally computed as a value

Array.reduce (function (Total,currentvalue,currentindex,arr), initialvalue);
1.total must be. The return value after the initial value or the result of the calculation
2.currentValue must be, current element.
3.currentIndex is optional. Index of the current element
4.arr is optional. The array object to which the current element belongs
5.initialValue is optional. The initial value passed to the function

JS array of higher order functions commonly used methods foreach, map, reduce

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.