<script type= "Text/javascript" >//Five iteration methods all accept two parameters: the function to run on each item and the scope to run the function (optional)//every (): Runs the given function for each item in the array. Returns True if the function returns true for each item. Filter (): Runs the given function for each item in the array. Returns an array of items that return true for the function. ForEach (): Runs the given function for each item in the array. The function does not return a value. Map (): Runs the given function for each item in the array. Returns a function that consists of the result of each function call. Some (): Runs the given function for each item in the array. Returns True if the function returns true for either item. var numbers = [1, 2, 3, 4, 5, 4, 3, 2, 1]; Every () and some () most closely resemble//every () item: The current traversal item, index: Current item, array: The array object itself var Everyresult = numbers.every (function (item, index, array) {return item > 2; }); alert (everyresult);//false//some () var someresult = numbers.some (function (item, index, array) { return item > 2; }); alert (someresult);//true//filter var filterresult = numbers.filter (function (item, index, array) { return item > 2; }); alert (Filterresult);//[3,4,5,4,3]//map () var mapresult = numbers. map (function (item, index, array) {return (item * 2); }); alert (Mapresult);//[2,4,6,8,10,8,6,4,2]//foreach Essentially, there is no difference between the For loop and Var foreachresult=numbers.foreach (function (i Tem,index,array) {alert (item)}); </script>
javascript--Iterative method