Wednesday, November 10, 2010

JavaScript gotcha

If you are using arrays of objects, make sure the last parameter doesn't end with a coma, for example:

test : [
{ myvar: 1},
{ myvar: 2},
{ myvar: 3},

This will work fine on Chrome and Firefox, but IE will consider the array to have an extra object . If your code uses the length of the array then it will crash because the last object will be null. How did I figure it out? The hard way...

No comments: