There is already a global name named name , it is window.name and it only accepts strings, so when you do
var name = ["one" , "two"];
in a global area and you will come back
console.log( name );
You are getting
"one, two"
and this is a type string, so name[1] is "n" , the second character in this string.
This is because you really set and get window.name , and it does not accept an array, so it runs toString() on everything you pass.
Change the variable name to something that is not yet used
source share