<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <Metaname= "Viewport"content= "Width=device-width, User-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <Metahttp-equiv= "X-ua-compatible"content= "Ie=edge"> <title>Document</title></Head><Body><Script> vararr= [1,2,3]; Arr.four= 4; Console.log (arr); Arr.foreach (Value= { /*if (value > 2) {break}*/Console.log (value)// the }) for(Let Iincharr) {Console.log (i);//' 0 ' 1 ' 2 ' four ' equals the object's key valueConsole.log (Arr[i])//1,2,3,4 equivalent to the value of the object } for(Let I of arr) {if(i> 2) { Break} console.log (i); //The value of each item in a number ofConsole.log (Arr[i]);//2,3,undefined equivalent to arr[1],arr[2],arr[3] } for(Let I of'my') {console.log (i);//' m ' Y ' } for(Let I of arr) {if(i> 2) { Break} console.log (i); // the }</Script></Body></HTML>
Summary: If traversing an array is best used for the, traversing the object with the for in
The difference between the for of traversal array and the foreach Traversal array: For of can use the break statement, foreach cannot
The difference between foreach,for in,for in JS