Javascript for..in looping over arguments ie.for( arg in arguments) does not work in IE8 but it works in Chrome 8

前端 未结 6 1477
刺人心
刺人心 2020-12-31 17:01

I faced this strange situation where foreach like construct of javascript does not work in IE but it works in FF. Well not all for..in just this special funcito

6条回答
  •  醉梦人生
    2020-12-31 17:58

    Well, it's supposed to work, so if it doesn't, the answer is as simple as "it's yet another bug in IE".

    But the real question here is why you're using for ... in to iterate over arrays or array-like objects (such as arguments) -- just use a simple for loop instead, which works in all major browsers:

    for (var i = 0; i < arguments.length; i++) {
      // do something with arguments[i]
    }
    

提交回复
热议问题