jQuery-未捕获的TypeError:对象0,0没有方法'split'-尝试对对象进行split() [英] jQuery - Uncaught TypeError: Object 0,0 has no method 'split' - Trying to split() on object

查看:78
本文介绍了jQuery-未捕获的TypeError:对象0,0没有方法'split'-尝试对对象进行split()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想使用逗号作为分隔符来拆分object.我知道有些东西需要拆分,因为当我单独输出它时...它成功地(循环地)说出了1,1和其他数字.

I'm just trying to split an object using commas as a delmiter. I know there is SOMETHING to split because when I output it by itself... it successfully says (over a loop) 1,1 and other numbers.

这是一个JSFiddle. http://jsfiddle.net/weka/5Xtwj/

Here is a JSFiddle. http://jsfiddle.net/weka/5Xtwj/

如果您在JavaScript部分中删除了这两行,它将可以正常工作,因为我不想获取数组的X.

If you remove these last two lines in the JavaScript section, it will work correctly because I am not wanting to get the X of the array.

var getX = path[index].split(",");
$("#debug").append("X: " + getX[0]);

PS-它使用此寻路脚本作为外部库.但这不是问题.

PS - It is using this pathfinding script as an external library. But that isn't the problem.

推荐答案

您可以使用 拆分 ,仅包含字符串,正如您在console.log上看到的那样,它是一个数组数组,所以这就是为什么出现此错误的原因. 您可以使用以下代码获取X值:

使用 切片 :

You can use split with only strings, as you can see on your console.log it's an array of arrays, so that's why you're getting this error.
You can get the X value with the following codes:

Using slice:

var getX = path[index].slice(0);

或:

var getX = path[index][0];

这篇关于jQuery-未捕获的TypeError:对象0,0没有方法'split'-尝试对对象进行split()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆