2011-03-07 2 views

답변

5

split() 메서드는 문자열을 하위 문자열 배열로 분할하고 새 배열을 반환하는 데 사용됩니다. 따라서, [1] 스플릿 어레이의 두 번째 요소를 나타낸다 window.location.hash.split("#")[1];

JavaScript Split Function

2

분할에서 발견 된 두 번째 요소에 액세스합니다.

3
var hashString = "#it #is #easy #to #understand #arrays"; 

/* 
hashString.split("#")[0] = "" 
hashString.split("#")[1] = "it " 
hashString.split("#")[2] = "is " 
hashString.split("#")[3] = "easy " 
hashString.split("#")[4] = "to " 
hashString.split("#")[5] = "understand " 
hashString.split("#")[6] = "arrays" 
*/ 

분할 ("#")은 [0] 빈 문자열 분할 함수는 "# 발생하기 때문이다 이유 "문자열의 맨 처음에 배열에서"# "을 제외하고 지금까지 전달한 모든 문자를 포함하는 항목을 만듭니다. 지금까지 아무 문자도 전달하지 않았기 때문에 빈 문자열 인 항목이 만들어집니다. [1] 어레이에 2 소자를 잡고,

var hashString = "it #is #easy #to #understand #arrays"; 

/* 
hashString.split("#")[0] = "it " 
hashString.split("#")[1] = "is " 
hashString.split("#")[2] = "easy " 
hashString.split("#")[3] = "to " 
hashString.split("#")[4] = "understand " 
hashString.split("#")[5] = "arrays" 
*/ 
2

(#) 인 해시를 없애기 쉬운 방법 ...

var hash = window.location.hash.substr(1); 
1

split() 배열을 반환 여기

다른 예제 [0]은 첫 번째 요소를 가져옵니다.

관련 문제