Set the length property of an object.
bool JS_SetArrayLength(JSContext *cx, JS::Handle<JSObject*> obj, uint32_t length);
||The context in which to change the length of the array. Requires request. In a
||The array to modify.|
||uint32_t||Number of array elements to set.|
JS_SetArrayLength sets the
.length property of an object
length indicates the number of elements.
JS_SetArrayLength(cx, obj, n) is exactly the same as setting the
length property of
JS_SetProperty. This is true even if
obj is not an
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.
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.
true. Otherwise it returns