- forEach loop through the array does not support out of no return value
/ * * * ForEach array traversal can not jump out of the way and for traversing the biggest difference * Its argument is a fall back function * parametric function out of the back: * Item: an array of every * index: index * / arr. forEach ( function Fn (Item, index) { // do something })
- some, every support out of the way, there is a return value
/ * * * Some parameters and every forEach as * some experience a true terminate traversal return true else return false * every terminate traversal encounters a false otherwise returns false true * @return Boolean {} * / var In Flag = arr.some ( function (item, index) { // here will traverse back to the first item will not traverse // here we look at optimizing the number of column, here only to traverse before two IF (index == 1 ) { // do something } return index ==. 1 })
- find, findIndex support out of the way, there is a return value
/ * * * Find, findIndex parameters and the same forEach * find a true encounter terminate traversal return to the condition that an otherwise empty object * findIndex terminate traversal encounters a true return to the condition that one subscript otherwise -1 * @return * / var index = arr.findIndex ( function (Item, index) { // that here only a rear traverse to traverse satisfying the condition will not return item.name, for == 'B' } ) the console.log (index) // index:. 1 var obj = arr.find ( function (Item, index) { // that will traverse a later meeting the conditions herein will not traverse the return item.name, for == 'B' }) the console.log (obj) // {name: "B", Age: 12 is}
- includes determining if a certain array elements, returns a Boolean
/ * * * Includes judged === * not suitable for determining the array is an array of objects unless the object reference * String number for primitive array * @return Boolean {} * / [ l, 2,3] .includes ( '. 1 ') // to false [l, 2,3] .includes (. 1) // to true arr.includes ({name:' A ', Age:. 11}) // to false
- reduce this complex, next Comments
Array traversal -ES6
Guess you like
Origin www.cnblogs.com/little-oil/p/12134080.html
Ranking