Obsolete since JSAPI 37
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
Determine if a specified numeric property exists.
Syntax
bool JS_LookupElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue 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 |
JS::HandleObject |
The object to search. |
index |
uint32_t |
The numeric id of the property to look up. |
vp |
JS::MutableHandleValue |
Out parameter. On success, *vp receives the stored value of obj[index] , or undefined 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 true
. If no such property exists, JS_LookupElement
sets *vp
to undefined
and returns true
(to indicate that no error occurred). On error or exception, JS_LookupElement
returns 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.