Are you thinking of an iterator? This is the upcoming standard, but it is only supported in javascript 1.7+, which in turn is only supported by Firefox as of now, and you'd have to use <script type="application/javascript;version=1.7">
... Chrome will claim to support JavaScript 1.7, but it will not actually support anything. [Don't ask me why they did this]
Just for the point of demonstrating it:
function yourIterator(arrayToGoThrough)
{
for(var i = 0; i < arrayToGoThrough.length; i++)
{
yield arrayToGoThrough[i];
}
}
var it = new yourIterator(["lol", "blargh", "dog"]);
it.next(); //"lol"
it.next(); //"blargh"
it.next(); //"dog"
it.next(); //StopIteration is thrown
Note that that is the new standard and you probably don't want to use it =)...
You could also "simulate" an iterator like this:
function myIterator(arrayToGoThrough){
this.i = 0;
this.next = function(){
if(i == arrayToGoThrough.length) //we are done iterating
throw { toString: function(){ return "StopIteration"; } };
else
return arrayToGoThrough[i++];
}
}
If you want to use the current standard, you could just iterate through your array
for(var i = 0; i < yourArr.length; i++) alert("yourArr["+i+"]: "+yourArr[i]);