aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/javascript/referencia/objetos_globales/array/isarray
diff options
context:
space:
mode:
Diffstat (limited to 'files/es/web/javascript/referencia/objetos_globales/array/isarray')
-rw-r--r--files/es/web/javascript/referencia/objetos_globales/array/isarray/index.html128
1 files changed, 128 insertions, 0 deletions
diff --git a/files/es/web/javascript/referencia/objetos_globales/array/isarray/index.html b/files/es/web/javascript/referencia/objetos_globales/array/isarray/index.html
new file mode 100644
index 0000000000..b2a115a814
--- /dev/null
+++ b/files/es/web/javascript/referencia/objetos_globales/array/isarray/index.html
@@ -0,0 +1,128 @@
+---
+title: Array.isArray()
+slug: Web/JavaScript/Referencia/Objetos_globales/Array/isArray
+tags:
+ - Array
+ - ECMAScript5
+ - JavaScript
+ - Referencia
+ - metodo
+ - polyfill
+translation_of: Web/JavaScript/Reference/Global_Objects/Array/isArray
+---
+<div>{{JSRef}}</div>
+
+<p>El método <code><strong>Array.isArray()</strong></code> determina si el valor pasado es un {{jsxref("Array")}}.</p>
+
+<pre class="brush: js">Array.isArray([1, 2, 3]); // true
+Array.isArray({foo: 123}); // false
+Array.isArray('foobar'); // false
+Array.isArray(undefined); // false
+</pre>
+
+<h2 id="Syntax" name="Syntax">Sintaxis</h2>
+
+<pre class="syntaxbox"><code>Array.isArray(<var>obj</var>)</code></pre>
+
+<h3 id="Parameters" name="Parameters">Parámetros</h3>
+
+<dl>
+ <dt><code>obj</code></dt>
+ <dd>El objeto a evaluar.</dd>
+</dl>
+
+<h3 id="Description" name="Description">Valor de retorno</h3>
+
+<p><code>true</code> si el objeto es un {{jsxref("Array")}}; en caso contrario, <code>false</code>.</p>
+
+<h2 id="Description" name="Description">Descripción</h2>
+
+<p>Si el objeto es un {{jsxref("Array")}}, devuelve <code>true</code>; <code>false</code>, en cualquier otro caso.</p>
+
+<p>Vea el artículo <a href="http://web.mit.edu/jwalden/www/isArray.html">“Determining with absolute accuracy whether or not a JavaScript object is an array”</a> para más detalles.</p>
+
+<h2 id="Examples" name="Examples">Ejemplos</h2>
+
+<pre class="brush: js">// las siguientes llamadas devuelven true
+Array.isArray([]);
+Array.isArray([1]);
+Array.isArray(new Array());
+Array.isArray(new Array('a', 'b', 'c', 'd'));
+Array.isArray(new Array(3));
+// Hecho poco conocido: Array.prototype es también un array:
+Array.isArray(Array.prototype);
+
+// todas las siguientes llamadas devuelven false
+Array.isArray();
+Array.isArray({});
+Array.isArray(null);
+Array.isArray(undefined);
+Array.isArray(17);
+Array.isArray('Array');
+Array.isArray(true);
+Array.isArray(false);
+Array.isArray({ __proto__: Array.prototype });
+</pre>
+
+<h3 id="instanceof_vs_isArray"><code>instanceof</code> vs <code>isArray</code></h3>
+
+<p>Al comprobar una instancia <code>Array</code>, <code>Array.isArray</code> es más recomendado que <code>instanceof</code> porque funciona a través de <code>iframes</code>.</p>
+
+<pre class="brush: js">var iframe = document.createElement('iframe');
+document.body.appendChild(iframe);
+xArray = window.frames[window.frames.length - 1].Array;
+var arr = new xArray(1,2,3); // [1,2,3]
+
+// Comprobando correctamente un Array
+Array.isArray(arr); // true
+// Considerado peligroso, porque no funciona a través de iframes
+arr instanceof Array; // false
+</pre>
+
+<h2 id="Polyfill" name="Polyfill">Polyfill</h2>
+
+<p>Ejecutar el siguiente código antes de cualquier otro código creará un <code>Array.isArray()</code> si no está disponible de forma nativa.</p>
+
+<pre class="brush: js">if (!Array.isArray) {
+ Array.isArray = function(arg) {
+ return Object.prototype.toString.call(arg) === '[object Array]';
+ };
+}
+</pre>
+
+<h2 id="Especificaciones" name="Especificaciones">Especificaciones</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Especificación</th>
+ <th scope="col">Estado</th>
+ <th scope="col">Comentario</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.4.3.2', 'Array.isArray')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td>Definición inicial. Implementado en JavaScript 1.8.5.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-array.isarray', 'Array.isArray')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-array.isarray', 'Array.isArray')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">Compatibilidad con navegadores</h2>
+
+<div>{{Compat("javascript.builtins.Array.isArray")}}</div>
+
+<h2 id="See_also" name="See_also">Vea también</h2>
+
+<ul>
+ <li>{{jsxref("Array")}}</li>
+</ul>