var arr = [1, 2, 3, 4, 5, 4, 3, 2, 1];
New Location method: IndexOf lastIndexOf
1.1 parameters indicating the value of the return index position (index starting from 0)
var index = Arr.indexof (4);
alert (index); 3
2.2 parameters when the first parameter indicates the starting position the second argument or the value
var index = arr.indexof (bis);
alert (index);//5
3. They look for array comparisons when ' = = = '
LastIndexOf
var index = Arr.lastindexof (2);
alert (index);//7
5 Methods for new iterations
1.every: Run a function for each element of the array if all returns True finally returns True if there is a return false the last result then returns false
var result = Arr.every (function (item, index, array) {
return item >= 1;
});
alert (result); True
2.filter: For each element of the array, perform a function to run the given function to perform the filtered result back
var result = Arr.filter (function (item, index, array) {
return item > 2;
});
alert (result); 3,4,5,4,3
3.forEach: Loop The value of each item in the array and execute a method
Arr.foreach (function (item, index, array) {
alert (item);//1,2,3,4,5,4,3,2,1
});
4.map running a function for each element of an array can return a new result after the function has finished executing
var result = Arr.map (function (item, index, array) {
return item*10;
});
alert (result); 10,20,30,40,50,40,30,20,10
5.some: Run a function for each element of the array if there is an item that returns true finally returns True if each item returns false The last result returns false
var result = Arr.some (function (item, index, array) {
return item >5;
});
alert (result);//false
Reduce reduceright
Variable start position is different
Previous value, current value, index position, array
var result = Arr.reduce (function (prev, cur, index, array) {
return prev + cur;
});
Alert (result)//25;
var result = Arr.reduceright (function (prev, cur, index, array) {
return prev + cur;
});
Alert (result)//25;
JAVASCRIPT_ECMA5 Array new features