IE9 JavaScript array initialization bug

后端 未结 2 1844
粉色の甜心
粉色の甜心 2021-01-02 05:54

Apparently JS implementation in IE9 contains (IMO, critical) bug in handling array literals.

In IE9 in some cases this code:

var a = [1,2,3,4,];
         


        
2条回答
  •  天涯浪人
    2021-01-02 06:07

    That's not a bug. That's exactly how it should behave. Microsoft did that on purpose. If you want an array with only 4 items, get rid of the last comma. Simple as that.

    If the results you're after is to have an extra, undefined value at the end, you're in luck. Even without the comma, it'll be undefined. It, and every single number after 3.

提交回复
热议问题