admin管理员组

文章数量:1415645

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?

Share Improve this question edited Oct 9, 2012 at 16:43 oz10 159k27 gold badges98 silver badges129 bronze badges asked Oct 9, 2012 at 13:22 croppio.croppio. 1,8835 gold badges28 silver badges45 bronze badges 4
  • 3 One of your "items" is not an array. – Pointy Commented Oct 9, 2012 at 13:24
  • Is items[i] an array? Add a debug line in your loop. console.log(items[i]); arr.push(items[i].join(',')); – epascarello Commented Oct 9, 2012 at 13:25
  • Since you have your developer tools open, what did you discover when you logged each item in the array you're looping? – I Hate Lazy Commented Oct 9, 2012 at 13:25
  • It would help if you showed what items is also. Code snipplet does not give enough data. – epascarello Commented Oct 9, 2012 at 13:26
Add a ment  | 

3 Answers 3

Reset to default 4

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!

本文标签: javascriptSCRIPT438 Object doesn39t support property or method 39join39Stack Overflow