JS_HasArrayLength

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

Revision Content

{{ Jsapi_ref_header("JS_HasArrayLength") }}

Determines if an object has an array length property.

Syntax

JSBool JS_HasArrayLength(JSContext *cx, JSObject *obj,
    jsuint *lengthp);
Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information. {{ Jsapi-requires-request() }}
obj JSObject * Array object to get the length of.
lengthp jsuint * Out parameter. On success, *lengthp receives the length of the array.

Description

JS_HasArrayLength determines if an object, obj, has a length property. If the property exists, JS_HasArrayLength stores the current value of the property in *lengthp.

On success, JS_HasArrayLength returns JS_TRUE, and *lengthp receives the current value of the length property. On failure, JS_HasArrayLength returns JS_FALSE, and the value left in *lengthp is undefined.

This function differs from JS_GetArrayLength in the treatment of errors and unusual cases, like when an object's length is negative or not a number. This function may return JS_FALSE without having reported any error or exception.

See Also

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

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

Revision Source

<p>{{ Jsapi_ref_header("JS_HasArrayLength") }}
</p><p>Determines if an object has an array length property.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="/en/JSBool" title="en/JSBool">JSBool</a> <strong>JS_HasArrayLength</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>Pointer to a JS context from which to derive runtime information.
{{ 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>Array object to get the length of.</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_HasArrayLength</code> determines if an object, <code>obj</code>, has a <code>length</code> property. If the property exists, <code>JS_HasArrayLength</code> stores the current value of the property in <code>*lengthp</code>.
</p><p>On success, <code>JS_HasArrayLength</code> returns <code>JS_TRUE</code>, and <code>*lengthp</code> receives the current value of the <code>length</code> property. On failure, <code>JS_HasArrayLength</code> returns <code>JS_FALSE</code>, and the value left in <code>*lengthp</code> is undefined.
</p><p>This function differs from <code><a href="/en/JS_GetArrayLength" title="en/JS_GetArrayLength">JS_GetArrayLength</a></code> in the treatment of errors and unusual cases, like when an object's <code>length</code> is negative or not a number. This function may return <code>JS_FALSE</code> without having reported any error or exception.
</p>
<h2 name="See_Also"> See Also </h2>
<p>{{ LXRSearch("ident", "i", "JS_HasArrayLength") }}
</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_GetElement" title="en/JS_GetElement">JS_GetElement</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