JS_GetArrayLength

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

Revision Content

{{ Jsapi_ref_header("JS_GetArrayLength") }}

Retrieves the number of elements in an array object.

Syntax

JSBool JS_GetArrayLength(JSContext *cx, JSObject *obj,
    jsuint *lengthp);
Name Type Description
cx JSContext * The context in which to look up the array's length. {{ Jsapi-requires-request() }}
obj JSObject * The array object to examine.
lengthp jsuint * Out parameter. On success, *lengthp receives the length of the array.

Description

JS_GetArrayLength reports the number of elements in an array object, obj. If the number of elements can be determined, JS_GetArrayLength reports the number of elements in lengthp and returns JS_TRUE. Otherwise, it returns JS_FALSE, and the value left in *lengthp is undefined.

See Also

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

JS_GetElement, JS_IsArrayObject, JS_SetArrayLength

Revision Source

<p>{{ Jsapi_ref_header("JS_GetArrayLength") }}
</p><p>Retrieves the number of elements in an array object.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="/en/JSBool" title="en/JSBool">JSBool</a> <strong>JS_GetArrayLength</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">jsuint</a> *lengthp);
</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 look up the array's length.
{{ 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 array object to examine.</td>
</tr>
<tr>
<td><code>lengthp</code></td>
<td><code><a href="/en/jsint" title="en/jsint">jsuint</a> *</code></td>
<td>Out parameter. On success, <code>*lengthp</code> receives the length of the array.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_GetArrayLength</code> reports the number of elements in an array object, <code>obj</code>. If the number of elements can be determined, <code>JS_GetArrayLength</code> reports the number of elements in <code>lengthp</code> and returns <code>JS_TRUE</code>. Otherwise, it returns <code>JS_FALSE</code>, and the value left in <code>*lengthp</code> is undefined.
</p>
<h2 name="See_Also"> See Also </h2>
<p>{{ LXRSearch("ident", "i", "JS_GetArrayLength") }}
</p><p><a href="/en/JS_GetElement" title="en/JS_GetElement">JS_GetElement</a>,
<a href="/en/JS_IsArrayObject" title="en/JS_IsArrayObject">JS_IsArrayObject</a>,
<a href="/en/JS_SetArrayLength" title="en/JS_SetArrayLength">JS_SetArrayLength</a>
</p>
Revert to this revision