title: How to iterate through Java collection in Javascript
body: <p>I'm trying to do scripting with Javascript in a Java program. I haven't found a way to iterate through a Java collection in Javascript. If I call the iterator() method for the collection, I get the method names instead of the elements.</p>
  
  <p>Here's a sample code:</p>
  
  <pre><code>function getValue(row, components) {
      var apartment = components.get(0);
      var rooms = apartment.getRooms();
      for (var room in rooms.iterator()) {
          println(room);
      }
      return rooms.toString();
  }
  </code></pre>
  
  <p>The apartment.getRooms() returns a collection of rooms. When I study the value returned by this function, I know that its content are correct, but the values that get printed are the method names.</p>
  
  <p>I invoke the Javascript from my Java program like this:</p>
  
  <pre><code>getInvocable().invokeFunction("getValue", row, components);
  </code></pre>