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
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
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"