programing

"string.split is not function" 오류의 원인은 무엇입니까?

iphone6s 2023. 7. 31. 21:12
반응형

"string.split is not function" 오류의 원인은 무엇입니까?

왜 내가...

Uncatched TypeError: string.split이 함수가 아닙니다.

...내가 달릴 때...

var string = document.location;
var split = string.split('/');

변경...

var string = document.location;

여기까지...

var string = document.location + '';

그 이유는document.location위치 개체입니다.기본값.toString()위치를 문자열 형식으로 반환하므로 연결이 이를 트리거합니다.


또한 문자열을 얻는 데 사용할 수도 있습니다.

아마도요.

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.href또는document.location.pathname대신.

절에서 if, 을 사용합니다.()예:

stringtorray = "xxxx,yyyyy,zzzzz";
if (xxx && (stringtoarray.split(',') + "")) { ...

언급URL : https://stackoverflow.com/questions/10145946/what-is-causing-the-error-string-split-is-not-a-function

반응형