From 39f2114f9797eb51994966c6bb8ff1814c9a4da8 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:36:08 +0100 Subject: unslug fr: move --- .../global_objects/array/isarray/index.html | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 files/fr/web/javascript/reference/global_objects/array/isarray/index.html (limited to 'files/fr/web/javascript/reference/global_objects/array/isarray') diff --git a/files/fr/web/javascript/reference/global_objects/array/isarray/index.html b/files/fr/web/javascript/reference/global_objects/array/isarray/index.html new file mode 100644 index 0000000000..bc07a159b0 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/array/isarray/index.html @@ -0,0 +1,117 @@ +--- +title: Array.isArray() +slug: Web/JavaScript/Reference/Objets_globaux/Array/isArray +tags: + - Array + - ECMAScript 5 + - JavaScript + - Méthode + - Reference + - polyfill +translation_of: Web/JavaScript/Reference/Global_Objects/Array/isArray +--- +
{{JSRef}}
+ +

La méthode Array.isArray() permet de déterminer si l'objet passé en argument est un objet {{jsxref("Array")}}, elle renvoie true si le paramètre passé à la fonction est de type Array et false dans le cas contraire.

+ +
Array.isArray([1, 2, 3]);   // true
+Array.isArray({toto: 123}); // false
+Array.isArray("tototruc");  // false
+Array.isArray(undefined);   // false
+
+ +

Syntaxe

+ +
Array.isArray(value)
+ +

Paramètres

+ +
+
value
+
La valeur dont on veut vérifier le type
+
+ +

Valeur de retour

+ +

true si la valeur est un tableau (une instance de {{jsxref("Array")}}), false sinon.

+ +

Description

+ +

Si l'objet indiqué en paramètre est un {{jsxref("Array")}}, la méthode renvoie true, sinon, elle renvoie false.

+ +

Voir aussi : « Determining with absolute accuracy whether or not a JavaScript object is an array » (en anglais) pour avoir plus de détails. Si on passe un objet {{jsxref("TypedArray")}} en argument, ce sera toujours la valeur false qui sera renvoyée.

+ +

Exemples

+ +
// Tous les appels suivant renvoient true
+Array.isArray([]);
+Array.isArray([1]);
+Array.isArray(new Array());
+Array.isArray(new Array('a', 'b', 'c'));
+Array.isArray(new Array(3));
+// Une petite anecdote: Array.prototype lui même est un Array
+Array.isArray( Array.prototype );
+
+// Tous les appels suivant renvoient 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 });
+
+ +

Prothèse d'émulation (polyfill)

+ +

Exécuter ce code avant tout les autres aboutira à la création de la méthode Array.isArray()si elle n'est pas nativement prise en charge par le navigateur.

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

Spécifications

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES5.1', '#sec-15.4.3.2', 'Array.isArray')}}{{Spec2('ES5.1')}}Définition initiale. Implémentée avec JavaScript 1.8.5.
{{SpecName('ES6', '#sec-array.isarray', 'Array.isArray')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-array.isarray', 'Array.isArray')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +
+ + +

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

+
+ +

Voir aussi

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