Skip to content Skip to sidebar Skip to footer

Jquery - Uncaught Typeerror: Object 0,0 Has No Method 'split' - Trying To Split() On Object

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 o

Solution 1:

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);

Or:

var getX = path[index][0];

Solution 2:

Error message tells you

Object0,0 has no method 'split'

It is an object [aka Array] and you are acting like it is a string. Why would you need to split it? Reference it.

var first = path[index][0];

Solution 3:

split can only be used on strings. Each path[index] is not a string, it's an array (look at the console output). You're seeing 0,0 because the array is being cast to a string for printing.

Answer : Instead of using path[index].split(",")[0], just use path[index][0].

enter image description here

Solution 4:

The value of path[index] is not a string, it's an array.

You can't split it, and you don't need to. You can use it right away:

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

http://jsfiddle.net/Guffa/5Xtwj/1/

Post a Comment for "Jquery - Uncaught Typeerror: Object 0,0 Has No Method 'split' - Trying To Split() On Object"