Why does JavaScript split() produce different output with different variable names?

后端 未结 3 1747
陌清茗
陌清茗 2021-01-18 05:38

Following is some codes and output from the Chrome Developers\' Console

Case 1:

var myarr = document.location.hostname.split(\".\");         


        
3条回答
  •  长情又很酷
    2021-01-18 06:14

    name in global scope is an empty string, so in the latter case you get the array returned by split transformed into a string "www,hostname,com". So name[0] gets you the first letter only.

提交回复
热议问题