なぜ私は...
キャッチされていない TypeError: string.split は関数ではありません
…走ると…
var string = document.location;
var split = string.split('/');
なぜ私は...
キャッチされていない TypeError: string.split は関数ではありません
…走ると…
var string = document.location;
var split = string.split('/');
これを変える...
var string = document.location;
これに...
var string = document.location + '';
これは、document.locationがLocation オブジェクトであるためです。デフォルトで.toString()は場所が文字列形式で返されるため、連結によってそれがトリガーされます。
文字列を取得するために使用することもできdocument.URLます。
多分
string = document.location.href;
arrayOfStrings = string.toString().split('/');
現在のURLが必要だと仮定します
これを実行
// you'll see that it prints Object
console.log(typeof document.location);
あなたがしたいdocument.location.toString()、またはdocument.location.href
document.location文字列ではありません。
おそらく代わりにdocument.location.hreforを使いたいでしょう。document.location.pathname