0
var names = ["pracas" , "prakash", "ramesh"];
document.getElementById("myh").innerHTML = names[1];

OUTPUT>> prakash

var name = ["pracas" , "prakash", "ramesh"];
document.getElementById("myh").innerHTML = name[1];

Output is >> r

Ivar
  • 5,377
  • 12
  • 50
  • 56

1 Answers1

0

No, you just have to make sure that the variable does not exist already. window.name does exist already, and your assignment collides with that. name = actually calls a setter, which casts the array to a string, and therefore you get the second strings character with name[1].

  window.name = ["a", "b"];
  console.log(window.name); // "a,b"
Jonas Wilms
  • 120,546
  • 16
  • 121
  • 140