JavaScript Array.from()
Esempio
Crea un array da una stringa:
Array.from("ABCDEFG")
Definizione e utilizzo
Il Array.from()
metodo restituisce una matrice da qualsiasi oggetto con una proprietà di lunghezza.
Il Array.from()
metodo restituisce una matrice da qualsiasi oggetto iterabile.
Array.da()
Array.from() è una proprietà statica dell'oggetto Array JavaScript.
Puoi usarlo solo come Array.from().
Usando x.from(), dove x è un array, restituirà undefined.
Sintassi
Array.from(object, mapFunction, thisValue)
Parametri
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 |
Valore di ritorno
Tipo | Descrizione |
Un array | I valori dell'oggetto iterabile. |
Supporto browser
Array.from()
è una funzione ECMAScript6 (ES6).
ES6 (JavaScript 2015) è supportato in tutti i browser moderni:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
Array.from()
non è supportato in Internet Explorer 11 (o versioni precedenti).