JavaScript Array.isArray()
Esempi
Controlla se un oggetto è un array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let result = Array.isArray(fruits);
Controlla se un altro tipo di dati è un array:
let text = "W3Schools";
let result = Array.isArray(text);
Definizione e utilizzo
Il isArray()
metodo restituisce true
se un oggetto è un array, altrimenti false
.
Array.isArray()
Array.isArray() è una proprietà statica dell'oggetto Array JavaScript.
Puoi usarlo solo come Array.isArray().
Usando x.isArray(), dove x è un array restituirà undefined.
Sintassi
Array.isArray(obj)
Parametri
Parameter | Description |
obj | Required. An object (or any data type) to be tested. |
Valore di ritorno
Tipo | Descrizione |
Un booleano |
true se l'oggetto è un array, altrimenti false . |
Supporto browser
isArray()
è una funzione ECMAScript5 (ES5).
ES5 (JavaScript 2009) completamente supportato in tutti i browser:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |