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
3 Answers
Reset to default 4Here'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
版权声明:本文标题:javascript - SCRIPT438: Object doesn't support property or method 'join' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745241707a2649365.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论