算法一,使用for in,:

var i=0

for (i in geo){

       document.write("The country is " + geo[i] +"<br />")

}

运行时间结果是最长的,即最没有效率的:(24ms

 

算法二,for循环

for (var i=0 ; i < geo.length; i++){

       document.write("The country is " + geo[i] +"<br />")

}

运行时间结果,比较有效率(17ms

 

算法三 for循环,将i.length存储为局部变量

for (var i=0, len=geo.length; i < len; i++){

       document.write("The country is " + geo[i] +"<br />")

}

运行时间结果,最高效。(14ms

posted on 2013-09-24 16:03  生之狼  阅读(264)  评论(0)    收藏  举报