var arr = [ '10','20','30','40','50' ] var num1 = arr.map( ( el,index )=>{ el = el*2 // arr还是[ '10','20','30','40','50' ] } ) 复制代码
var arr = [ '10','20','30','40','50' ] var num1 = arr.forEach( ( el,index )=>{ el = el*2 // 此时arr变为[ '20','40','60','80','100' ] } ) 复制代码
var arr = [10,20,30,40,50] var num1 = arr.filter( ( item,index )=>{ return item > 30 } ) // 此时num1为[40,50] 复制代码
var arr = [10,20,30,40,50] var num1 = arr.every( ( item,index )=>{ return item > 30 } ) // 此时num1为false,因为不是所有有数字都比30小 复制代码
var arr = [10,20,30,40,50] var num1 = arr.some( ( item,index )=>{ return item > 40 } ) // 此时num1为true因为里面有元素比40大 复制代码
*对数组中所有元素调用函数,返回值是最后的结果
var arr = [10,20,30,40,50] var num1 = arr.reduce( ( item,index )=>{ return item + index } ) // 此时num1为150,因为是将该数组中每一项进行叠加处理 复制代码
var arr = [10,20,30,40,50] var num1 = arr.push( 60 ) // num1 = 6, 复制代码
var arr = [10,20,30,40,50] var num1 = arr.pop() // num1 = 50 返回值是删除的那项 复制代码
var arr = [10,20,30,40,50] var num1 = arr.shift() // num1 = 10 返回值是删除的那项 复制代码
var arr = [10,20,30,40,50] var num1 = arr.unshift( 60 ) // num1 = 6 复制代码
var arr = [10,20,30,40,50] var num1 = Array.isArray( arr ) // num1 = true 复制代码
var arr = [10,20,30,40,50] var str = [70,80] var num1 = arr.concat( str ) // 此时num1 = [10,20,30,40,50,70,80] // es6数组简单拼接方法: [...arr,...str] 复制代码
var arr = [10,20,30,40,50] var num1 = arr.toString( ) 复制代码
var arr = [10,20,30,40,50] var num1 = arr.join( ) 复制代码
var arr = [10,20,30,40,50] var num1 = arr.splice( 0,1,60 ) // 此时num1 = 【10】,arr = [60,20,30,40,50] 复制代码
Array.from(arrayLike, mapFn, thisArg) 复制代码