Because it goes out of scope when the loop ends.
So you should have
var linking;
for (i=0;i<=4;i++)
{
linking= links[i];
}
But furthermore, what are you trying to do here? You overwrite linking four times. Do you want to display all of the links? If so, you can concatenate them like:
var linking = "";
for (i=0;i<=4;i++)
{
linking = linking + links[i] + " ";
}
Edit: the commenters are right; I did forget that there is no block scoping in Javascript. Did this fix your code? I can't imagine that it did. The only other thing that I can think of is that links[4]
is undefined, and then you would be assigning undefined
to linking
.
Anyway, I can't delete this because it's been accepted, but if anyone else comes up with a more useful answer, feel free to unaccept this one.