var arr = [1, 2, 3, 4, 5, 4, 3, 2, 1];
New Add Position method: IndexOf LastIndexOf
When 1.1 arguments are passed, the value returns the index position (index starting from 0)
var index = Arr.indexof (4);
alert (index); 3
2. When the first parameter represents the second argument or value at the start position of the 2 parameter
var index = arr.indexof (4,4);
alert (index); 5
3. They look for array comparisons when ' = = '
LastIndexOf
var index = Arr.lastindexof (2);
alert (index); 7
5 New iterative methods
1.every: Run a function for each element of an array if both returns True last returns True if one returns false the last result 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 of the given function to execute the filtered result returned
var result = Arr.filter (function (item, index, array) {return
item > 2;
});
alert (result); 3,4,5,4,3
3.forEach: Loops The value of each item in the array and executes a method
Arr.foreach (function (item, index, array) {
alert (item);//1,2,3,4,5,4,3,2,1
});
4.map the operation of a function for each element of an array can be performed after the function completes and the new result is returned
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 an array if one of the entries returns True, the last returns true if each entry returns false the final result returns false
var result = Arr.some (function (item, index, array) {return
item >5;
});
alert (result); False
Reduce reduceright
Variable starts at different positions
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;
The above JAVASCRIPT_ECMA5 array of new features is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.