Length of Array Differs In Internet Explorer With Trailing Comma

Viewed 10044

I'm currently working with some data using Javascript that is in the form of an array. The array may contain an empty entry at the end, such as [1,2,]. In Google Chrome and Firefox, the length of that example would be 2; however, in IE, the length is 3.

In short: Internet Explorer is giving a different length for an array in Javascript than Google Chrome and Firefox. Is there a way to standardize this behavior across all browsers?

Code:

var a = [1,];
alert(a.length);

EDIT:

A lot of answers are saying not to have a trailing comma, however, the data is given to me in this way.

3 Answers
Related