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
  • 6,138
  • 12
  • 49
  • 61

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
  • 132,000
  • 20
  • 149
  • 151