Array has an extra undefined element in IE 8

I’ve run into this problem when I was writing a new piece of JavaScript code that went through an array and did something on all it’s elements. We needed to support the latest FF, Chrome and IE 8+. In almost all browsers it was working fine. However, in IE 8 my array had an extra undefined element at the end. My array definition looked something like this:

var arr = [1, 2, 3,]

The problem is the trailing comma at the end. IE 8 thinks that the comma means there is an extra element in the array and because it is not specified it becomes undefined.  Then if you go through all the element and try to call some function on them, you will get an error stating that the desired function is not available on that element. To fix this, just remove the trailing comma.

var arr = [1, 2, 3]