Reputation: 1265
I have the following JavaScript code that executes fine in Firefox, but in Internet Explorer 9 generates the error message:
SCRIPT5007: Unable to get value of the property '2': object is null or undefined
var items = [
[1,2,3],
[4,5,6],
[7,8,9],
[5,5,5],
];
var myString = "";
for(var i = 0; i < items.length; i++) {
myString += items[i][2];
}
alert("Joined number: " + myString);
Upvotes: 0
Views: 89
Reputation:
IE adds a null element after a trailing commas. Remove the comma after [5,5,5],
To explain, items.length === 4
in FF, but 5
in IE. The 5th item is null
, and null[2]
does not exist.
Upvotes: 3