Loop through array, print with string.

Posted by Adam on Stack Overflow See other posts from Stack Overflow or by Adam
Published on 2010-05-23T16:51:40Z Indexed on 2010/05/23 19:31 UTC
Read the original article Hit count: 119

Filed under:
|

I have a simple array like:

var myArr=["one","two","three"];

an I have a counting loop, which increases the value of var i by one.

What I want to do is print the next value from the array each time the loop runs, next to a text string, like so:

alert('value number '+myArr[i]+);

But for some reason I can't get this to work. The following code works, so I'm assuming I'm not calling the counter right:

alert('value number '+myArr[0]+);

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about array