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