var arr = [1,2,3,4];
ForEach
Arr.foreach ((Item,index,arr) = { Console.log (item)//result is 1,2,3,4})
Filter
Filter filters out values in the array that do not meet the criteria, returns a new array, and does not change the value of the original array. var c=arr.filter ((Item,index,arr) = {return item > 2//new array for [3,4] filters the item that satisfies the condition returns a new array})
Map
var d=arr.map ((Item,index,arr) =>{return item*3;//walk through each item to return})
Some
var e=arr.some ((Item,index,arr) =>{return item>3;//returns True if satisfied, terminates the loop});
Every
var f=arr.every ((Item,index,arr) = {return item > 0//result is false})//Iterate through the array for each item, each item returns TRUE, and the final result is true. When any one of the items returns false, stop the traversal and return false. Does not change the original array console.log (C,D,E);
Sort
For two elements x and Y, if you thinkx < y, then return-1 if it is consideredx = = y, 0 is returned if it is consideredx > Y, it returns the results that 1//looks normal: [' Google ', ' apple ', ' Microsoft '].sort ();//[' Apple ', ' Google ', ' Microsoft '];//Apple ranked last: [' Google ', ' Apple ', ' Microsoft '].sort ();//[' Google ', ' Microsoft ', ' apple ']//incomprehensible results: [Ten, 1, 2].sort ();//[1, 10, 2, 20] according to the correspondingASCIICode to sort, while the lowercase letter AASCIIAfter the code is in capital letters but sort is also a higher-order function that can be customized by receiving a comparison function to implement a custom collation
var arr = [' Google ', ' apple ', ' Microsoft '];arr.sort (function (s1, s2) { x1 = s1.touppercase (); x2 = S2.touppercase (); if (X1 < x2) { return-1;//x < y } if (X1 > x2) { return 1;//x > Y } return 0;// x = = y}); [' Apple ', ' Google ', ' Microsoft ']
Array manipulation of array APIs (filter, map, some, every, sort)