What is causing the error `string.split is not a function`?
Change this...
var string = document.location;
to this...
var string = document.location + '';
This is because document.location
is a Location object. The default .toString()
returns the location in string form, so the concatenation will trigger that.
You could also use document.URL
to get a string.
maybe
string = document.location.href;arrayOfStrings = string.toString().split('/');
assuming you want the current url
run this
// you'll see that it prints Objectconsole.log(typeof document.location);
you want document.location.toString()
or document.location.href