I am encountering this error on Internet Explorer 9.0 under F12 development tools, in the following statement:
arr = [];
for (i = 0; i < items.length; i ++) {
console.log(items[i]);
arr.push(items[i].join(','));
}
This method work on every browser except IE. Why isn't it working?
I am encountering this error on Internet Explorer 9.0 under F12 development tools, in the following statement:
arr = [];
for (i = 0; i < items.length; i ++) {
console.log(items[i]);
arr.push(items[i].join(','));
}
This method work on every browser except IE. Why isn't it working?
console.log(items[i]); arr.push(items[i].join(','));
– epascarello
Commented
Oct 9, 2012 at 13:25
Here's my guess (since we're lacking information).
It could be a bination of the following:
You're testing in IE8, or if you're using IE9, you're in Quirks Mode
When you built the Array, you included a trailing ,
In Quirks Mode, or in IE8 and lower, if you include a trailing ma in Array literal syntax, it'll (incorrectly) add an extra item the end of the Array.
This means your last item will be undefined
, and you'll get an Error when you use .join()
.
In IE8 and lower, or any version in Quirks Mode, you'll get the following:
var items = [
["foo"],
["bar"],
["baz"], // <-- trailing ma
];
alert(items.length); // 4 (should be 3)
This issue was resolved by changing arr = [] to var arr = [];
Not quite an answer, but would have helped me...
I thought I was using the join method as a static method of the Array type (which probably betrays my C# history) as follows:
var s = Array.join(myArray, ",");
and unsurprisingly I can't find anyone else using that syntax. The surprising thing is that it worked in Firefox. Didn't in IE, which is what led me here.
Changing to the more conventional
var s = myArray.join(",");
fixed it!