The problem is that you are overwriting the
name
property, which
is the name of the window[
^]. By changing this to an array, it will be automatically converted to a string, so
name[0]
will take a single char. To fix this problem, just rename your
name
variable to something else.
function makeHello(myName) {
myName[myName.length] = "Hello " + myName[0] + " " + myName[1];
}
var myName = new Array('Ima','Reader');
makeHello(myName);
alert(myName[2]);