最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript split function in chrome gives unexpected results - Stack Overflow

programmeradmin1浏览0评论

Here is the piece of code

str = "a,b,c";
name = str.split(",");

The name variable shows up as 'object' type in Firefox and 'string' type in chrome Why is that happening ? Here is the jsfiddle /

Also the name variable stores the value "a,b,c" instead of the split array in chrome /

Here is the piece of code

str = "a,b,c";
name = str.split(",");

The name variable shows up as 'object' type in Firefox and 'string' type in chrome Why is that happening ? Here is the jsfiddle http://jsfiddle/XujYT/17/

Also the name variable stores the value "a,b,c" instead of the split array in chrome http://jsfiddle/XujYT/23/

Share edited Nov 17, 2012 at 9:50 Sethunath K M asked Nov 17, 2012 at 9:35 Sethunath K MSethunath K M 4,7614 gold badges30 silver badges42 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 13

Because name is a global variable used by chrome, and it’s not possible to override it without unexpected results. Try:

var name = str.split(","); // always use var for local variables!
发布评论

评论列表(0)

  1. 暂无评论