Subj : Re: Naming an Array To : Dave Baldwin From : Brendan Eich Date : Thu Jun 05 2003 07:53 pm Dave Baldwin wrote: > I'm trying to construct an array from my application using > JS_NewArrayObject and populating it with JS_DefineElement. However, I > can't figure out how to name it so that I can access it in JavaScript. > > Hope someone can help. array_obj = JS_NewArrayObject(cx, 0, NULL); for (i = 0; i < len; i++) JS_DefineElement(cx, array_obj, i, values[i], NULL, NULL, JSPROP_ENUMERATE); JS_DefineProperty(cx, parent_obj, "my_array", OBJECT_TO_JSVAL(array_obj), NULL, NULL, JSPROP_ENUMERATE); Don't forget to root array_obj, e.g., by setting *rval = OBJECT_TO_JSVAL(array_obj) before the loop. /be .