Array.length anybody?

I came across a fun little issue today that I think should have been more obvious to me. Apparently, and I can’t believe I’m saying this: IE and Firefox parse Javascript differently. Take the following code:

var foo = [
{'one': 1},
{'two': 2},
];

What should the length be? In Firefox 2 & 3 the length is 2, but in IE7/IE8 the length is 3. I can’t confirm this, but considering I figured this out due to a *NEW* bug in one of our products, I think this is somewhat new in IE.

On a side note, it’s interesting that IE even parses the above considering the following code will break:

var foo = {
'one': 1,
'two': 2,
}

The difference here is of course that foo in the second example is an object, whereas the first example it’s an array.

This entry was written by MET , posted on Wednesday December 03 2008at 06:12 pm , filed under programming and tagged , , . Bookmark the permalink . Post a comment below or leave a trackback: Trackback URL.

Leave a Reply

You must be logged in to post a comment.