JavaScript iterative methods, merging methods

Source: Internet
Author: User

1. Iterative Methods

  every (FN): runs the given function for each item in the array, and returns True if the function returns true for each item.

  Some (FN): runs the given function for each item in the array, and returns True if the function returns true for either item.

 Filter (FN): runs the given function for each item in the array, and returns a type that matches a certain condition.

  ForEach (FN): runs the given function for each item in the array, with no return value.

  Map (FN): each item in the array runs the given function, returning an array that consists of the results of each function call.

2. Merge method

ECMAScript5 added 2 methods for merging arrays:reduce () and reduceright ().

  reduce (): traverse through to the end one at a start of the first entry.

reduceright (): iterates to the first item of the array, starting with the last item in the array.

    var values = [1, 2, 3, 4, 5];    var sum = values.reduce (function (prev, cur, index, array) {        return prev + cur;    });    alert (sum);    As a result, it's just the opposite.    var sum2=values.reduceright (function (prev,cur,index,array) {        return prev+cur;    });    alert (SUM2);

  

JavaScript iterative methods, merging methods

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.