Five iteration methods and two merging methods for js arrays (recommended)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>Unt titled document</title><script> window.onload = function(){ //every() is equivalent to logic and var arr = [1,2,3,4,5,6,7,8]; var everyRes = arr.every(function(item,index,array){ return (item>2); }); alert(everyRes); //some() is equivalent to logic or var someRes = arr.some(function(item,index,array){ return (item>2); }); alert(someRes); //filter() returns the array of given conditions var filterRes = arr.filter(function(item,index,array){ return (item>2); }); alert(filterRes); //map() returns the array of given conditions var mapRes = arr.map(function(item,index,array){ return (item*2); }); alert(mapRes);//forEach() has no return value and can be self-tested} //Reduce() merge method accepts the passed function and the initial value as the basis for merge (optional //The function to be passed receives four functions, the previous value, the current value, the index item, the array object var sum = arr.reduce(function(prev,cur,index,array){ return prev + cur; }); alert(sum); //ReduceRight() merge method is essentially the same as the reduce() method, the difference is that it starts from back to front var in the edge. sum2 = arr.reduceRight(function(pre,cur,index,array){ return pre + cur; }); alert(sum2);</script></head><body></body></html>The above five iteration methods and two merging methods of js array (recommended) are all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.