_.each _.map _.filter JavaScript syntax

Source: Internet
Author: User

1.forEach (): No return value, just call func for each element
In simple terms, each value in the array is traversed sequentially, executing the function function
If you only need to operate on an array element, you do not need to return any values when applicable

var shuzu=[1,2,3,4]var a= _.each (Shuzu,function(NUM1) {      return  NUM1})

Console.log (a);
The result is 1,2,3,4

Note that there is no condition for NUM1 to be included in Num1 +1, the result is still 1,2,3,4 four numbers

2.map (): Returns a new array with each element as the result of calling Func
is to handle each element with the Func function, placing the processed result as an element into the new array
Each element of the array needs to be processed to get the processed array, applicable

var shuzu=[1,2,3,4]var b= _.map (Shuzu,function(num2) {    return num2 * 3;    }) Console.log (b); //

But the output is an array.

3.filter (): Returns an array of elements that conform to the Func condition
Each element in the array is conditionally judged, the element that matches the condition is stored in the array, and the array is finally returned
Array elements need to be filtered according to certain criteria for

var shuzu=[1,2,3,4var c= _.filter (Shuzu,function(num3) {return num3 > 2        }) Console.log (c)
3,4

The output is also an array

_.each _.map _.filter JavaScript syntax

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.