2
A
回答
5
split()方法用于将字符串拆分为一个子字符串数组,并返回新数组。因此,[1]
表示分割阵列的第二元件window.location.hash.split("#")[1];
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]是一个空字符串,因为分割函数遇到一个“# “在字符串的最开始处,此时它会创建一个数组入口,其中包括迄今为止所传递的每个字符,但”#“除外。由于它迄今没有传递任何字符,因此会创建一个空字符串的条目。
下面是另一个示例:
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()
返回一个数组,[1]
抓住第二元件阵列中的[0]
会抓住第一个元素。
相关问题
- 1. 这个C代码是做什么的?
- 2. 这个clojure代码是做什么的?
- 3. 这个rails代码是做什么的?
- 4. 这个python代码是做什么的?
- 5. 这个javascript代码是做什么的?
- 6. 这个xkcd代码是做什么的?
- 7. 这个VHDL代码是做什么的?
- 8. 这个C代码是做什么的?
- 9. 这个C++代码段做了什么?
- 10. 这个线程代码在做什么?
- 11. 这个python代码试图做什么
- 12. 这个matlab代码在做什么?
- 13. 这个javascript代码在做什么?
- 14. 这个bash代码在做什么?
- 15. Javascript:这个代码做什么?
- 16. 这个javascript代码在做什么?
- 17. 这个PHP代码做了什么?
- 18. 为什么在这个C代码中malloc i + 1的参数?
- 19. 这个函数在Facebook的JavaScript源代码中做了什么?
- 20. 这个运算符在这个代码中做什么&=? (c#)
- 21. 在这段代码中做什么[0]?
- 22. 这行代码在这段代码中做了什么?
- 23. 这行代码是做什么的?球员=(球员%2)? 1:2;
- 24. 对数和指数,这个汇编代码是做什么的?
- 25. List [:] = List在这个基数排序代码中做什么?
- 26. 这行代码是做什么的?
- 27. 这是什么代码做perl的
- 28. 这段C代码是做什么的?
- 29. 这行C#代码是做什么的?
- 30. jquery - 这行代码是做什么的?