Tableau JavaScript.from()
Exemple
Créez un tableau à partir d'une chaîne :
Array.from("ABCDEFG")
Définition et utilisation
La Array.from()
méthode renvoie un tableau à partir de n'importe quel objet avec une propriété de longueur.
La Array.from()
méthode renvoie un tableau à partir de n'importe quel objet itérable.
Tableau.de()
Array.from() est une propriété statique de l'objet JavaScript Array.
Vous ne pouvez l'utiliser que comme Array.from().
L'utilisation de x.from(), où x est un tableau renverra undefined.
Syntaxe
Array.from(object, mapFunction, thisValue)
Paramètres
Parameter | Description |
object | Required. The object to convert to an array. |
mapFunction | Optional. A map function to call on each item. |
thisValue | Optional. A value to use as this for the mapFunction |
Valeur de retour
Taper | La description |
Un tableau | Les valeurs de l'objet itérable. |
Prise en charge du navigateur
Array.from()
est une fonctionnalité ECMAScript6 (ES6).
ES6 (JavaScript 2015) est pris en charge dans tous les navigateurs modernes :
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
Array.from()
n'est pas pris en charge dans Internet Explorer 11 (ou version antérieure).