This project has moved. For the latest updates, please go here.

Returning Arrays to Javascript

Oct 17, 2013 at 12:36 AM
Paul,

I want to return an array of objects to the Javascript code. Is this possible? It doesn't seems so and instead I was going to return a wrapper object that has a count and a getItem( i ) method on it to be used in a for loop. Any suggestions or alternatives before I riddle my code with this approach?

Thanks!
-andy
Coordinator
Oct 17, 2013 at 3:48 AM
Try something like this:
public MyClass : ObjectInstance
{
  ... constructor, etc ...
  public ArrayInstance MyMethod()
  {
    object[] myArray = ...  // should work with string[], int[], double[] or ObjectInstance[] as well.
    return this.Engine.Array.New(myArray);
  }
}
Oct 18, 2013 at 12:26 PM
Paul,

Works like a charm. Thank you for the very quick response!

-andy