We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

JS SetElement

Assign a value to a numeric property of an object.


JSBool JS_SetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
Name Type Description
cx JSContext * The context in which to set the element. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
obj JSObject * The object to modify, commonly an Array object.
index jsint Index number of the element to set.
vp jsval * In/out parameter. *vp is the value to assign to the element. JS_SetElement ordinarily leaves *vp unchanged, but a JSClass.addProperty hook or non-default setter may modify it.


JS_SetElement assigns a value to a numeric property of an object. It behaves like the JavaScript expression obj[index] = v.

JS_SetElement first converts index to a jsid. Then it sets the specified property as though by calling JS_SetPropertyById(cx, obj, id, vp).

On success, JS_SetElement returns JS_TRUE and the value left in *vp is left unchanged unless an addProperty hook or setter modified it. On error or exception, JS_SetElement returns JS_FALSE and the value left in *vp is unspecified.

MXR ID Search for JS_SetElement

Document Tags and Contributors

Last updated by: Jorend,