-
for方法
var arr = [1]; for(var i = 0; i < arr.length; i++){ console.info(arr[i]); //1 }
-
for...in方法
var arr = [1,2]; for(var index in arr){ console.info(index,arr[index]); //0 1, 1 2 }
-
map方法
var arr = [1]; var newArr = arr.map(function(item,index){ console.info(item,index); //1 0 return item; });
-
forEach方法
var arr = [1]; var newArr = arr.forEach(function(item,index){ console.info(item,index); //1 0 return item; });
-
filter方法
var arr = [1,2]; var newArr = arr.filter(function(item,index){ return item > 1; }); console.info(newArr); //[2]
-
some方法
var arr = [1,2]; var newArr = arr.some(function(item,index){ return item > 1; }); console.info(newArr); //true
-
every方法
var arr = [1,2]; var newArr = arr.every(function(item,index){ return item > 1; }); console.info(newArr); //false
-
reduce方法
var arr = [1,2,3]; var total = arr.reduce(function(pre,cur,index,arr){ console.info(pre); //0,1,3 return pre + cur; },0); console.info(total); //6
-
reduceRight方法
var arr = [1,2,3]; var total = arr.reduceRight(function(pre,cur,index,arr){ console.info(pre); //4,5,7 return pre + cur; },4); console.log(total); //10
-
for...of方法
var arr = [1,2]; for(var item of arr){ console.info(item); //1, 2 }
网友评论