JS_GetElement

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_GetElement
  • Revision title: JS_GetElement
  • Revision id: 147003
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment no wording changes; page display name changed to 'JS_GetElement'

Revision Content

{{ Jsapi_ref_header("JS_GetElement") }}

Find a specified numeric property of an object and return its current value.

Syntax

JSBool JS_GetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
Name Type Description
cx JSContext * The context in which to perform the property lookup. {{ Jsapi-requires-request() }}
obj JSObject * The object to search for the element.
index jsint Index of the element to look up.
vp jsval * Out parameter. On success, *vp receives the current value of the element, if it exists, and JSVAL_VOID otherwise.

Description

JS_GetElement examines a specified JS object, obj, and its prototype chain, for an element or numeric property numbered index.

If the element exists, JS_GetElement sets *vp to the element's current value. If not, it sets *vp to JSVAL_VOID and returns JS_TRUE (to indicate no error occurred). If the search fails with an error or exception, JS_GetElement returns JS_FALSE, and the value left in *vp is undefined.

See Also

{{ LXRSearch("ident", "i", "JS_GetElement") }}

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

Revision Source

<p>{{ Jsapi_ref_header("JS_GetElement") }}
</p><p>Find a specified numeric property of an object and return its current value.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="/en/JSBool" title="en/JSBool">JSBool</a> <strong>JS_GetElement</strong>(<a href="/en/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/en/JSObject" title="en/JSObject">JSObject</a> *obj, <a href="/en/jsint" title="en/jsint">jsint</a> index, <a href="/en/jsval" title="en/jsval">jsval</a> *vp);
</pre>
<table class="fullwidth-table">
<tbody><tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code>cx</code></td>
<td><code><a href="/en/JSRuntime" title="en/JSRuntime">JSContext</a> *</code></td>
<td>The context in which to perform the property lookup.
{{ Jsapi-requires-request() }}</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code><a href="/en/JSObject" title="en/JSObject">JSObject</a> *</code></td>
<td>The object to search for the element.</td>
</tr>
<tr>
<td><code>index</code></td>
<td><code><a href="/en/jsint" title="en/jsint">jsint</a></code></td>
<td>Index of the element to look up.</td>
</tr>
<tr>
<td><code>vp</code></td>
<td><code><a href="/en/jsval" title="en/jsval">jsval</a> *</code></td>
<td>Out parameter. On success, <code>*vp</code> receives the current value of the element, if it exists, and <code><a href="/en/JSVAL_VOID" title="en/JSVAL_VOID">JSVAL_VOID</a></code> otherwise.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_GetElement</code> examines a specified JS object, <code>obj</code>, and its prototype chain, for an element or numeric property numbered <code>index</code>.
</p><p>If the element exists, <code>JS_GetElement</code> sets <code>*vp</code> to the element's current value. If not, it sets <code>*vp</code> to <code><a href="/en/JSVAL_VOID" title="en/JSVAL_VOID">JSVAL_VOID</a></code> and returns <code>JS_TRUE</code> (to indicate no error occurred). If the search fails with an error or exception, <code>JS_GetElement</code> returns <code>JS_FALSE</code>, and the value left in <code>*vp</code> is undefined.
</p>
<h2 name="See_Also"> See Also </h2>
<p>{{ LXRSearch("ident", "i", "JS_GetElement") }}
</p><p><a href="/en/JS_DefineElement" title="en/JS_DefineElement">JS_DefineElement</a>, <a href="/en/JS_DeleteElement" title="en/JS_DeleteElement">JS_DeleteElement</a>, <a href="/en/JS_GetArrayLength" title="en/JS_GetArrayLength">JS_GetArrayLength</a>, <a href="/en/JS_IsArrayObject" title="en/JS_IsArrayObject">JS_IsArrayObject</a>, <a href="/en/JS_LookupElement" title="en/JS_LookupElement">JS_LookupElement</a>, <a href="/en/JS_NewArrayObject" title="en/JS_NewArrayObject">JS_NewArrayObject</a>, <a href="/en/JS_SetArrayLength" title="en/JS_SetArrayLength">JS_SetArrayLength</a>, <a href="/en/JS_SetElement" title="en/JS_SetElement">JS_SetElement</a>
</p>
Revert to this revision