2.7.1 Arr.foreach ()
Parameters and Meanings
var arr = [' A ', ' B ', ' C ', ' d ', ' e '];
var RT = Arr.foreach (function (A, B, c) {
console. Log (' Three parameters ', a, b, c);
} ) ;
console. log (' return value ', RT);
The first 1 parameters are each element in the array
The first 2 parameters are indexed
The first 3 parameters are the original array
Characteristics
The 1> ForEach method executes the callback function once for each item in the array that has a valid value in ascending order , those that have been deleted (using the Delete method, and so on) or uninitialized items that are skipped (but do not include those values undefined items)
In the 1> callback function, whatever you return , the end result is undefined .
2.7.2 Arr.map ()
Parameters and Meanings
var arr = [' A ', ' B ', ' C ', ' d ', ' e '];
var RT = Arr.map (function (A, B, c) {
console. Log (' Three parameters ', a, b, c);
} ) ;
console. log (' return value ', RT);
The first 1 parameters are each element in the array
The first 2 parameters are indexed
the 3 parameter is an array of return values for each call to the callback function
Characteristics
The map method invokes the callback function sequentially for each element in the original array . callback The return value (including undefined) after each execution is combined to form a new array. the callback function is only called on the indexed index, and those indexes that have never been assigned a value or deleted by using delete are not called.
Case
Add 2 to each item in the array
var arr = [' A ', ' B ', ' C ', ' d ', ' e '];
var RT = Arr.map (function (item, index, arr) {
console. Log (' Three parameters ', item, index, ARR);
return item + 2;
} ) ;
console. log (' return value ', RT);
2.7.3 Arr.some ()
Parameters and Meanings
var arr = [1, 2, 3, 4, 5];
var RT = Arr.some (function (item, index, arr) {
console. Log (' Three parameters ', item, index, ARR);
return item > 9;
} ) ;
console. log (' return value ', RT);
judging each item in the array, if there is one that satisfies the item > 9 then the some method returns true, otherwise false
Characteristics
Some callback callback " " Span style= "font-family: Equal line" > (can be converted to a Boolean true some true some return false callback has a value " is called on the index , it is not invoked on indexes that have been deleted or have never been assigned a value.
var arr = [1, 2, 3, 4, 5];
var RT = Arr.some (function (item, index, arr) {
console. Log (' Three parameters ', item, index, ARR);
return item > 3;
} ) ;
console. log (' return value ', RT);
ForEach () map () some () [array expansion method]