[JSmentor] Array with for-in
※ 引述《TonyQ (沉默是金。)》之銘言:
http://goo.gl/muajC
Another discussion for "for-in" with a array.
We are talking about the difference between
var ary = [1,2,3,4,5];
for(var k in ary){
alert(k+":"+ary[k]);
}
and
for(var i=0,len=k.length;i<len;++i){
alert(i+":"+k[i]);
}
They look similar , but actully they do have different
behavior in this case.
I strongly recommand you that not to use for-in with a Array,
unless you know what you are doing and what you need.
Also , it's worth to read it for more detail with Array.
like how browser iterate the array. :)
--
網頁上拉近距離的幫手 實現 GMail豐富應用的功臣
數也數不清的友善使用者體驗 這就是javascript
歡迎同好到 AJAX 板一同討論。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 198.203.175.175
※ 編輯: TonyQ 來自: 198.203.175.175 (03/22 23:50)
※ 編輯: TonyQ 來自: 198.203.175.175 (03/22 23:53)
※ 編輯: TonyQ 來自: 72.21.245.243 (03/23 07:53)
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章