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]+);
Make sure that you're properly incrementing the loop counter (it should start at zero and run until the highest index in the array), and that the stray + at the end of your alert line is removed.
for (var i = 0; i < myArr.length; ++i) {
alert('value at index [' + i + '] is: [' + myArr[i] + ']');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With