이 자바 스크립트가 해시 태그에서 분리된다는 것을 이해합니다. 그러나 1은 무엇을 나타낼까요?이 코드에서 1 번 번호는 무엇입니까
window.location.hash.split("#")[1];
이 자바 스크립트가 해시 태그에서 분리된다는 것을 이해합니다. 그러나 1은 무엇을 나타낼까요?이 코드에서 1 번 번호는 무엇입니까
window.location.hash.split("#")[1];
split() 메서드는 문자열을 하위 문자열 배열로 분할하고 새 배열을 반환하는 데 사용됩니다. 따라서, [1]
스플릿 어레이의 두 번째 요소를 나타낸다 window.location.hash.split("#")[1];
분할에서 발견 된 두 번째 요소에 액세스합니다.
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"
*/
(#
) 인 해시를 없애기 쉬운 방법 ...
var hash = window.location.hash.substr(1);
split()
배열을 반환 여기
[0]
은 첫 번째 요소를 가져옵니다.