--- title: Array.isArray() slug: Web/JavaScript/Reference/Global_Objects/Array/isArray translation_of: Web/JavaScript/Reference/Global_Objects/Array/isArray original_slug: Web/JavaScript/Referencje/Obiekty/Array/isArray ---
Array.isArray() to metoda, która zwraca true jeśli obiekt jest tablicą, fałsz jeśli nie jest.
Array.isArray(obj)
objZobacz artykuł “Determining with absolute accuracy whether or not a JavaScript object is an array” , aby poznać więcej szczegółów.
// poniższe przykłady zwrócą true
Array.isArray([]);
Array.isArray([1]);
Array.isArray(new Array());
// Mało znany fakt: Array.prototype sam w sobie jest tablicą:
Array.isArray(Array.prototype);
// poniższe przykłady zwrócą 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 });
Jeśli metody Array.isArray() nie jest natywnie dostępna, poniższy kod ją utworzy.
if (!Array.isArray) {
Array.isArray = function(arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
}
| Specyfikacja | Status | Komentarz |
|---|---|---|
| {{SpecName('ES5.1', '#sec-15.4.3.2', 'Array.isArray')}} | {{Spec2('ES5.1')}} | Wstępna definicja. Implementacja od JavaScript 1.8.5. |
| {{SpecName('ES6', '#sec-array.isarray', 'Array.isArray')}} | {{Spec2('ES6')}} |
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | {{CompatChrome("5")}} | {{CompatGeckoDesktop("2.0")}} | {{CompatIE("9")}} | {{CompatOpera("10.5")}} | {{CompatSafari("5")}} |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile("2.0")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
Based on Kangax's compat table.