JS_LookupElement

Determine if a specified numeric property exists.

Syntax

JSBool JS_LookupElement(JSContext *cx, JSObject *obj,
    jsint index, jsval *vp);
Name Type Description
cx JSContext * The context in which to look up the property. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
obj JSObject * The object to search.
index jsint The numeric id of the property to look up.
vp jsval * Out parameter. On success, *vp receives the stored value of obj[index], or JSVAL_VOID if the element does not exist.

Description

JS_LookupElement examines a specified JavaScript object, obj, for a numeric property numbered index.

Note: In the JavaScript language, numeric properties (also called "elements") are just ordinary properties whose names are numeric strings. For example, obj[6] is always exactly the same as obj["6"]. The ECMAScript standard also specifies this behavior: see ECMA 262-3 §11.2.1, step 6. So any call to JS_LookupElement is equivalent to a call to JS_LookupProperty passing a numeric string for the name.

If the property obj[index] exists, JS_LookupElement sets *vp to the property's stored value and returns JS_TRUE. If no such property exists, JS_LookupElement sets *vp to JSVAL_VOID and returns JS_TRUE (to indicate that no error occurred). On error or exception, JS_LookupElement returns JS_FALSE, and the value left in *vp is undefined.

JS_LookupElement does not distinguish between a property with a value of undefined and a property that does not exist.

See Also

MXR ID Search for JS_LookupElement

JS_DefineElement, JS_DeleteElement, JS_GetArrayLength, JS_GetElement, JS_IsArrayObject, JS_NewArrayObject, JS_SetArrayLength, JS_SetElement

Document Tags and Contributors

Contributors to this page: Tservo, MMondor, Nickolay, Jorend, Dria
Last updated by: Jorend,