Retrieve the number of elements in an array object.


JSBool JS_GetArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp);
Name Type Description
cx JSContext * The context in which to look up the array's length. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
obj JSObject * The object to examine.
lengthp jsuint * Out parameter. On success, *lengthp receives the length of the array.


JS_GetArrayLength gets the .length property of obj as though by calling JS_GetProperty and converts it to a 32-bit unsigned integer as though by calling JS_ValueToECMAUInt32. If obj is an array (see JS_IsArrayObject), this is guaranteed to succeed, because the .length property of an array is always a number and can't be deleted or redefined.

On success, JS_GetArrayLength stores the length in *lengthp and returns JS_TRUE. On failure, it reports an error and returns JS_FALSE, and the value left in *lengthp is undefined.

See Also

MXR ID Search for JS_GetArrayLength

JS_GetElement, JS_SetArrayLength

Document Tags and Contributors

Contributors to this page: Nickolay, Callek, Crowder, MMondor, Tservo, Dria, Jorend
Last updated by: Jorend,