Rhino’s for…each loop is a non-standard JavaScript extension and causing some problems, e.g. with JSDoc.
Rewriting it is quite straight-forward, either by using the for…of loop, the Array.forEach() method, or the good old for…in syntax:
:bulb: For the for…of loop to work, the VERSION_ES6 flag must be enabled in Rhino!
var collection = [1, 2, 3];
// Rhino-specific for…each loop
for each (let value in collection) {
console.log(value);
}
// for…of loop
for (let value of collection) {
console.log(value);
}
// Array.forEach method
collection.forEach(value => console.log(value));
collection = {a: 1, b: 2, c: 3};
// for…in loop – Rhino does not support `Object.values()`
for (let key in collection) {
let value = collection[key];
console.log(value);
}
Rhino’s
for…each
loop is a non-standard JavaScript extension and causing some problems, e.g. with JSDoc.Rewriting it is quite straight-forward, either by using the
for…of
loop, theArray.forEach()
method, or the good oldfor…in
syntax: