First, the basic
All I'm following example, are used in the array is, so first on the front
1.arr.indexOf(v);
- a. returns the first occurrence of the subscript
- B. two parameters. From behind parameter represents the subscript Find
- c. If not present, return -1.
2.arr.lastIndexOf(v);
- a. From looking forward after the return is the first time the number backwards subscript
- b. Accept two parameters, the second parameter, which represents the start index from
eg:
3.arr.forEach (function (value, index, ARR) {
// arr array entries
// index subscript
// arr array itself
})
NOTE: forEach () does not return value must be received by the return value of the variable
4.arr.map (function (value, index, ARR) {
return value +1; + 1 // to each item in the array, and then mapped into a new array, without affecting the original array
})
// return value .
eg: Each value in the array are increased by one
5.arr.reduce (function (ACC, CUR, index, ARR) {
// accumulator ACC
// value of the value of each array
// index subscript
// array itself ARR
return acc + value; // accumulated
return acc * value; // multiplicative
return acc / value; // tired other
return acc - value; // Accumulated
})
Note: Each quadrature sum, must have an initial value, like we sum when the sum of the initial value of 0, when Quadrature, produce an initial value of 1. In short, there are different calculations for different initial values, and reduce our approach, just to provide a totalizer, the underlying method, has set an initial value for each calculation, we only need to direct calculation.
6.arr.filter (function (value, index, ARR) {
return filter conditions;
})
eg: a digital filter of less than 5
NOTE: In the api m after several map (including map), each has a return value api