What is the problem?


#1


when i put this codes here:

var name=["richard","shelly","david","tracy","sun"];
for (i=0;i<name.length;i++)
{
    console.log("I know someone called"+" "+name[i]);
}

it output is:
I know someone called r
I know someone called i
I know someone called c
I know someone called h
I know someone called a
I know someone called r
I know someone called d
I know someone called ,
I know someone called s
I know someone called h
I know someone called e
I know someone called l
I know someone called l
I know someone called y
I know someone called ,
I know someone called d
I know someone called a
I know someone called v
I know someone called i
I know someone called d
I know someone called ,
I know someone called t
I know someone called r
I know someone called a
I know someone called c
I know someone called y
I know someone called ,
I know someone called s
I know someone called u
I know someone called n

when I change name to names, it shows all right which means:

var names=["richard","shelly","david","tracy","sun"];
for (i=0;i<names.length;i++)
{
    console.log("I know someone called"+" "+names[i]);
}

I know someone called richard
I know someone called shelly
I know someone called david
I know someone called tracy
I know someone called sun


#2

name is a reserved word in the global (window) scope. Use var names = instead.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.