Extended html5 array new api array added several classic traversal filtering methods, which are very convenient. This prevents the use of the for loop in the transition. The prototype extension of javascript objects provides a unified front-end call interface. The Code is as follows: copy the code (function (_ window) {// some methods are added to the array // The forEach method traverses the array from start to end, and the specified function is called for each array element to provide the current element, the current index and Array are passed to the Function Array as parameters. prototype. forEach | (Array. prototype. forEach = function (fun) {for (var I = 0; I <this. length; I ++) {fun (this [I], I, this) ;}} // The map Method traverses the array and calls the specified function. Finally, an array is returned, an Array consists of all function return values. prototype. map | (Array. prototype. map = function (fun) {var returnArray = []; for (var I = 0; I <this. length; I ++) {returnArray. push (fun (this [I], I, this);} return returnArray;}) // filter is a handsome selector of an array. it traverses the array, calls the specified function, and returns a new array, if the function returns true, the returned array is added. Array. prototype. filter | (Array. prototype. filter = function (fun) {var returnArray = []; for (var I = 0; I <this. length; I ++) {if (fun (this [I], I, this) {returnArray. push (this [I]);} return returnArray;}) // calls the specified function to traverse the array. If all functions return true, every returns true; otherwise, false. Array. prototype. every | (Array. prototype. every = function (fun) {if (this. length = 0) return true; // every should end the loop as soon as possible for (var I = 0; I <this. length; I ++) {if (! Fun (this [I], I, this) {return false ;}return true ;}) // some traversal array calls the specified function, if a function returns true, true is returned. If all functions return false, false Array is returned. prototype. some | (Array. prototype. some = function (fun) {if (this. length = 0) return false; // some should end the loop as soon as possible for (var I = 0; I <this. length; I ++) {if (fun (this [I], I, this) {return true ;}} return false ;}) // The reduce traversal array calls the specified function (the function requires two parameters). Each time the return value and the next element of the called function are used as the function parameters to continue calling. // The Array summation operation is very useful. prototype. reduce | (Array. prototype. reduce = function (fun, initval) {if (this. length = 0) return ""; if (this. length = 1) {return initval? Fun (initval, this [0]): this [0];} var val = initval, firstindex = initval? 0: 2; if (! Initval) {val = fun (this [0], this [1]) ;}for (var I = firstindex; I <this. length; I ++) {val = fun (val, this [I]);} return val ;}) // same as reduce, reduceRight only traverses the Array from right to left. prototype. reduceRight | (Array. prototype. reduceRight = function (fun, initval) {if (this. length = 0) return ""; if (this. length = 1) {return initval? Fun (initval, this [0]): this [0];} var val = initval, firstindex = initval? This. length-1: this. length-3; if (! Initval) {val = fun (this [this. length-1], this [this. length-2]) ;}for (var I = firstindex; I> = 0; I --) {val = fun (val, this [I]);} return val ;})} (window );