JavaScript-1.5 Reference

JS_SetArrayLength Function

Summary

Specifies the number of elements for an array object.

Syntax

JSBool JS_SetArrayLength(JSContext *cx, JSObject *obj,
    jsint length);
NameTypeDescription
cxJSContext *Pointer to a JS context from which to derive runtime information.
objJSObject *Array object for which to set the number of array elements.
lengthjsintNumber of array elements to set.

Description

JS_SetArrayLength specifies the number of elements for an array object, obj. length indicates the number of elements. If JS_SetArrayLength successfully sets the number of elements, it returns JS_TRUE. Otherwise it returns JS_FALSE.

You can call JS_SetArrayLength either to set the number of elements for an array object you created without specifying an initial number of elements, or to change the number of elements allocated for an array. If you set a shorter array length on an existing array, the elements that no longer fit in the array are destroyed.

Notes

Setting the number of array elements does not initialize those elements. To initialize an element call JS_DefineElement. If you call JS_SetArrayLength on an existing array, and length is less than the highest index number for previously defined elements, all elements greater than or equal to length are automatically deleted.

See Also

Groups [ Function ]
Documents [ LXR ID Search ]
Entries [ JS_AliasElement | JS_DefineElement | JS_DeleteElement | JS_GetArrayLength | JS_GetElement | JS_IsArrayObject | JS_LookupElement | JS_NewArrayObject | JS_SetElement ]

This page was generated by APIDOC