JS_SetArrayLength |
Function |
|
Summary
Specifies the number of elements for an array object.
|
Syntax
JSBool JS_SetArrayLength(JSContext *cx, JSObject *obj,
jsint length);
Name | Type | Description |
cx | JSContext * | Pointer to a JS context from which to derive runtime information.
|
obj | JSObject * | Array object for which to set the number of array elements.
|
length | jsint | Number 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
|