Why am I getting...
Uncaught TypeError: string.split is not a function
...when I run...
var string = document.location;_x000D_
var split = string.split('/');
_x000D_
This question is related to
javascript
jquery
split
maybe
string = document.location.href;
arrayOfStrings = string.toString().split('/');
assuming you want the current url
run this
// you'll see that it prints Object
console.log(typeof document.location);
you want document.location.toString()
or document.location.href
In clausule if, use ()
.
For example:
stringtorray = "xxxx,yyyyy,zzzzz";
if (xxx && (stringtoarray.split(',') + "")) { ...
document.location
isn't a string.
You're probably wanting to use document.location.href
or document.location.pathname
instead.
Source: Stackoverflow.com