Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCRIPT438: Object doesn't support property or method 'join'

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?

like image 704
croppio.com Avatar asked May 28 '26 01:05

croppio.com


1 Answers

Here's my guess (since we're lacking information).

It could be a combination 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 comma 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 comma
];

alert(items.length); // 4 (should be 3)
like image 102
I Hate Lazy Avatar answered May 30 '26 13:05

I Hate Lazy