Following is some codes and output from the Chrome Developers’ Console
Case 1:
var myarr = document.location.hostname.split("."); //typed
undefined //output
myarr[0] //typed
"ptamz" //output: ONE
Case 2:
var name = document.location.hostname.split("."); //typed
undefined //output
name[0] //typed
"p" //output: TWO
Why are the two outputs (commented Output: ONE, and Output: TWO) different?
Screenshot:

nameis a property ofwindow. It appears that when you try to set that property to an array, the keys are joined with a comma (the result of callingtoStringon an array). So you are actually setting thewindow.nameproperty to the concatenation of each element ofdocument.location.hostname.split("."), separated by commas.Here’s a screenshot from my Chrome console demonstrating what happens:
The reason
name[0]then results inpis that you can access the characters of strings using square brackets:Edit
As others have mentioned, this will only be the case in the global scope. You are free to declare a variable named
nameinside a descendant scope. Although, obviously, omitting thevarkeyword in this case would still result in you accessingwindow.name: