--- title: Array.isArray() slug: Web/JavaScript/Reference/Global_Objects/Array/isArray tags: - Array - ECMAScript5 - JavaScript - Method - Reference - polyfill translation_of: Web/JavaScript/Reference/Global_Objects/Array/isArray --- <div>{{JSRef}}</div> <p>Die <code><strong>Array.isArray()</strong></code> Funktion prüft, ob das übergebene Objekt ein {{jsxref("Array")}} ist.</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">Syntax</h2> <pre class="syntaxbox"><code>Array.isArray(<var>obj</var>)</code></pre> <h3 id="Parameters" name="Parameters">Parameter</h3> <dl> <dt><code>value</code></dt> <dd>Der zu überprüfende Wert.</dd> </dl> <h3 id="Rückgabewert">Rückgabewert</h3> <p>Wenn der Wert ein {{jsxref("Array")}} ist wird <code>true</code> zurückgegeben, andernfalls <code>false</code>.</p> <h2 id="Description" name="Description">Beschreibung</h2> <p>Wenn der Wert ein {{jsxref("Array")}} ist, wir <code>true</code> zurückzugeben, andernfalls <code>false</code>.</p> <p>Eine detailliertere Beschreibung ist im Artikel <a href="http://web.mit.edu/jwalden/www/isArray.html">Determining with absolute accuracy whether or not a JavaScript object is an array</a> enthalten (auf Englisch). Wird eine {{jsxref("TypedArray")}}-Instanz geprüft, wird immer <code>false</code> zurückgegeben.</p> <h2 id="Beispiele">Beispiele</h2> <h3 id="Einsatz_von_Array.isArray">Einsatz von Array.isArray</h3> <pre class="brush: js">// die folgenden Ausdrücke geben true zurück Array.isArray([]); Array.isArray([1]); Array.isArray(new Array()); Array.isArray(new Array('a', 'b', 'c', 'd')); Array.isArray(new Array(3)); // wenig bekannt: Array.prototype ist selbst ein Array. Array.isArray(Array.prototype); // die folgenden Ausdrücke geben alle false zurück Array.isArray(); Array.isArray({}); Array.isArray(null); Array.isArray(undefined); Array.isArray(17); Array.isArray("Array"); Array.isArray(true); Array.isArray(false); Array.isArray(new Uint8Array(32)); Array.isArray({ __proto__ : Array.prototype }); </pre> <h3 id="instanceof_vs_isArray"><code>instanceof</code> vs <code>isArray</code></h3> <p>Wenn auf eine <code>Array</code> Instanz geprüft wird, ist <code>Array.isArray</code> besser geeignet als <code>instanceof</code>, weil es auch mit <code>iframes</code> funktioniert.</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] // Richtiges Prüfen für Arrays Array.isArray(arr); // true // Als nicht richtig angesehen, weil es nicht mit iframes funktioniert arr instanceof Array; // false </pre> <h2 id="Compatibility" name="Compatibility">Polyfill</h2> <p>Der folgende Code implementiert die Methode, wenn <code>Array.isArray()</code> nicht nativ unterstützt wird.</p> <pre class="brush: js">if(!Array.isArray) { Array.isArray = function (vArg) { return Object.prototype.toString.call(vArg) === "[object Array]"; }; } </pre> <h2 id="Spezifikationen">Spezifikationen</h2> <table class="standard-table"> <tbody> <tr> <th scope="col">Spezifikation</th> </tr> <tr> <td>{{SpecName('ESDraft', '#sec-array.isarray', 'Array.isArray')}}</td> </tr> </tbody> </table> <h2 id="Browserkompatibilität">Browserkompatibilität</h2> <div> <p>{{Compat("javascript.builtins.Array.isArray")}}</p> </div> <h2 id="Siehe_auch">Siehe auch</h2> <ul> <li>{{jsxref("Array")}}</li> </ul>