JS_SetArrayLength 编辑
Set the length property of an object.
Syntax
bool
JS_SetArrayLength(JSContext *cx, JS::Handle<JSObject*> obj, uint32_t length);
Name | Type | Description |
---|---|---|
cx | JSContext * | The context in which to change the length of the array. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
obj | JS::Handle<JSObject*> | The array to modify. |
length | uint32_t | Number of array elements to set. |
Description
JS_SetArrayLength
sets the .length
property of an object obj
. length
indicates the number of elements. JS_SetArrayLength(cx, obj, n)
is exactly the same as setting the length
property of obj
to n
using JS_SetProperty
. This is true even if obj
is not an Array
object.
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.
On success, JS_SetArrayLength
returns true
. Otherwise it returns false
.
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论