From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- .../global_objects/array/isarray/index.html | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 files/it/web/javascript/reference/global_objects/array/isarray/index.html (limited to 'files/it/web/javascript/reference/global_objects/array/isarray') diff --git a/files/it/web/javascript/reference/global_objects/array/isarray/index.html b/files/it/web/javascript/reference/global_objects/array/isarray/index.html new file mode 100644 index 0000000000..d7aaf864bf --- /dev/null +++ b/files/it/web/javascript/reference/global_objects/array/isarray/index.html @@ -0,0 +1,133 @@ +--- +title: Array.isArray() +slug: Web/JavaScript/Reference/Global_Objects/Array/isArray +tags: + - Array + - ECMAScript 5 + - JavaScript + - Referenza + - metodo + - polyfill +translation_of: Web/JavaScript/Reference/Global_Objects/Array/isArray +--- +
{{JSRef}}
+ +

Il metodo Array.isArray() determina se il valore passato è un {{jsxref("Array")}}.

+ +
Array.isArray([1, 2, 3]);  // true
+Array.isArray({foo: 123}); // false
+Array.isArray('foobar');   // false
+Array.isArray(undefined);  // false
+
+ +

Sintassi

+ +
Array.isArray(value)
+ +

Parametri

+ +
+
value
+
Il valore da verificare.
+
+ +

Valore di ritorno

+ +

true se il valore è un {{jsxref("Array")}}; altrimenti, false.

+ +

Descrizione

+ +

Se il valore è un {{jsxref("Array")}}, viene ritornato true; altrimenti viene ritornato false.

+ +

Vedi l'articolo “Determining with absolute accuracy whether or not a JavaScript object is an array” per maggiori dettagli. Data un'istanza {{jsxref("TypedArray")}}, viene ritornato sempre false.

+ +

Esempi

+ +
// tutte le seguenti chiamate ritornano true
+Array.isArray([]);
+Array.isArray([1]);
+Array.isArray(new Array());
+Array.isArray(new Array('a', 'b', 'c', 'd'));
+Array.isArray(new Array(3));
+// Fatto poco noto: Array.prototype stesso è un array:
+Array.isArray(Array.prototype);
+
+// tutte le seguenti chiamate ritornano 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(new Uint8Array(32));
+Array.isArray({ __proto__: Array.prototype });
+
+ +

instanceof vs isArray

+ +

Quando si verifica l'istanza ArrayArray.isArray è preferito su instanceof perché funziona attraverso gli iframes.

+ +
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]
+
+// Verifica corretta dell'array
+Array.isArray(arr);  // true
+// Considerato dannoso, perché non funziona attraverso iframe
+arr instanceof Array; // false
+
+ +

Polyfill

+ +

L'esecuzione del seguente codice prima di qualsiasi altro codice creerà Array.isArray() se non è nativamente disponibile.

+ +
if (!Array.isArray) {
+  Array.isArray = function(arg) {
+    return Object.prototype.toString.call(arg) === '[object Array]';
+  };
+}
+
+ +

Specifiche

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificaStatoCommento
{{SpecName('ES5.1', '#sec-15.4.3.2', 'Array.isArray')}}{{Spec2('ES5.1')}}Definizione iniziale Implementato in JavaScript 1.8.5.
{{SpecName('ES6', '#sec-array.isarray', 'Array.isArray')}}{{Spec2('ES6')}}
{{SpecName('ESDraft', '#sec-array.isarray', 'Array.isArray')}}{{Spec2('ESDraft')}}
+ +

Compatibilità con i browser

+ +
+ + +

{{Compat("javascript.builtins.Array.isArray")}}

+
+ +

Vedi anche

+ + -- cgit v1.2.3-54-g00ecf