CosmoCode
  • Great software.

  • Bright people.

  • Happy customers!

CosmoCode GmbH
  • Home
  • Skills
  • About Us
  • References
  • Blog
  • Open Source
←
All blogposts
→

Rhino Javascript Array secrets

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

Detlef Hüttemann, 05/12/2006 2:35 p.m.

Rhino Javascript Array secrets

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.

Read more

  • Ausprobiert: rome
  • rhino again
  • JSON and Rhino Pitfalls
  • JavaScript: Fixing the Closure Scope in Loops
  • The return of flat formel
  • JavaScript closures and the mysterious this
  • addEvent()
  • Collections.sort in Rhino
  • Bildschirm dekorieren mit Yahoo!
  • JQuery

Contact

Thank you for your interest!
Get in contact:

CosmoCode GmbH

Prenzlauer Allee 36G
10405 Berlin

Phone: +49 30 814 50 40 70

Fax: +49 30 2809 7093


mail: info@cosmocode.de

CosmoCode GmbH  
   

© CosmoCode 2021 | Imprint | Data Privacy | Cookies verwalten

Close
Deutsch English
  • Jobs