Array Looping properties: For,map,filter,foreach
Conclusion: Except for, none of the others can terminate the loop by return false.
Code
<!doctype html>content= "Width=device-width, User-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" > <meta http-equiv= "x-ua-compatible" content= "Ie=edge" > <title>Document</title>vardata = [1,2,3,4,5] vararr =[{text:' Zhang San ', Age:9}, {text:' John Doe ', age:20}, {text:' Harry ', age:20}, {text:' Zhao Liu ', age:20} ] functionA () { for(vari=0; i<5; i++) {console.log (i); return false } } functionB () {Data.filter (v={console.log (v)return falseConsole.log (haha) }) } functionC () {returnArr.map (V, k) = = { if(v.age>10) { returnV.text}Else { return‘‘ } }) } functiond () {Arr.foreach (V, k)={console.log (v)return false})} Console.log (A ()) Console.log (' A---------------------------') Console.log (b ()) Console.log (' B---------------------------') Console.log (c ()) Console.log (' C---------------------------') Console.log (d ()) Console.log (' D---------------------------') Console.log (' For after ');</script></body>Results
Reference: http://es6.ruanyifeng.com/
ES6 Array new features