Arrays are easy to in scripting languages and lists are commonly used in Java.
So when using Rhino to script your application, you often have to deal with lists - most of the time you have to iterate over it.
A straightforward solution to solve
this problem is
for ( var iter=list.iterator(); iter.hasNext(); ) {
var item= iter.next();:
}
But this is not very 'javascript' like. A alternative way is to work on (Java) Arrys; Rhino's for-loop can handle them too:
for each (var item in list.toArray() ) {
}
Thats pretty more elegant, isnt it?
Dont forget to use the 'each'. Without that, you just will get indices (0,1,2) instead of the values.
You can use the toArray idion in many cases, but jwhen performance is critical, i will jrecommend the iterater method; the toArray() construction may be performance-consuming.