The newly added API interface forEach map filter in Array in ES5 some every indexOf lastIndexOf reduce reduceRight
var array = [23,48,66,2];
ForEach: loop, traversing array; no return value. Similar to for Loop
array.forEach(function( value, index, array ) { console.log(value); return value * value;} );
Map: ing meaning, ing returns a new array with a returned value; filterArr: returns a new object
var mapArr = array.map(function(value, index, array ){ return value * value;});
Filter: the meaning of filtering; return value; filterArr: return the new array after filtering
var filterArr = array.filter(function(value, index, array ) { if ( value > 20 ) { return true; } return false;});
EveryArr: Meaning of each and every item; return value; every: Return boolean true or false;
var everyArr = array.every(function(value, index, array){ if ( value > 1 ) { return true; }});
IndexOf: the first is the retrieved value, and the second is the position to be retrieved starting from 0.
console.log(array.indexOf(23,0));
LastIndexOf: the first is the value to be retrieved, and the second is the position to be retrieved starting from arr. length-1.
console.log(array.lastIndexOf(2,10));
// Initial settings
Previous = initialValue = 1, current = 2
// The first iterationPrevious = (1 + 2) = 3, current = 3
// The second iterationPrevious = (3 + 3) = 6, current = 4
// The third iterationPrevious = (6 + 4) = 10, current = undefined (Exit)
var reduce = [1,2,3,4].reduce(function(prev, curr, index, array) { console.log(prev +" "+ curr); return prev + curr; });
// Initial settings
Index = 3, previous = initialValue = 4, current = 3
// The first iterationIndex = 2, previous = (4-3) = 1, current = 2
// The second iterationIndex = 1, previous = (1-2) =-1, current = 1
// The third iterationIndex = 0, previous = (-1 + 1) = 0, current = undefined (Exit)
var reduceRight = [1,2,3,4].reduceRight(function(prev, curr, index, array) { if ( index == 0 ) { return prev + curr; } return prev - curr; });
console.log(reduceRight);