The three methods are as follows: viewsourceprint? For (vari0; I & lt; arr. length; I ++) viewsourceprint? For (variinarr) viewsourceprint? For (vari0, lenarr. length; I & lt; len; I +... S
The three methods are as follows:
View sourceprint? For (var I = 0; I <arr. length; I ++)
View sourceprint? For (var I in arr)
View sourceprint? For (var I = 0, len = arr. length; I <len; I ++)
Let's take a look at the test running interface:
Looking at the corresponding three results, the efficiency of the three statements is very different:
In this case, the most efficient execution is the third type:
View sourceprint? For (var I = 0, len = arr. length; I <len; I ++)
Declare the variable first and then perform loop judgment. The efficiency is much higher than that of traversing the array, and it is much faster than getting the array length through loop!
Below is the page source code:
View sourceprint?