Questa traduzione è incompleta. Collabora alla traduzione di questo articolo dall’originale in lingua inglese.
Il metodo toString()
ritorna una stringa che rappresenta l'array e i suoi elementi.
Sintassi
arr.toString()
Valore ritornato
Una stringa che rappresenta gli elementi dell'array.
Descrizione
L'oggetto Array
sovrascrive il metodo toString
di Object
. Per gli oggetti di tipo Array, il metodo toString
unisce gli elementi dell'array e ritorna una stringa contentente tutti gli elementi dell'array separati da una virgola.
JavaScript invoca automaticamente il metodo toString
quando un array deve essere rappresentato come testo o quando è presente un riferimento all'array in una concatenzazione di stringhe.
ECMAScript 5 semantics
Starting in JavaScript 1.8.5 (Firefox 4), and consistent with ECMAScript 5th edition semantics, the toString()
method is generic and can be used with any object. Object.prototype.toString()
will be called, and the resulting value will be returned.
Specifiche
Specification | Status | Comment |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | Definizione iniziale. Implementato in JavaScript 1.1. |
ECMAScript 5.1 (ECMA-262) The definition of 'Array.prototype.toString' in that specification. |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Array.prototype.toString' in that specification. |
Standard | |
ECMAScript Latest Draft (ECMA-262) The definition of 'Array.prototype.toString' in that specification. |
Draft |
Compatibilità browser
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | Yes | Yes | 1 | Yes | Yes | Yes |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | Opera Android | iOS Safari | Samsung Internet |
---|---|---|---|---|---|---|---|
Basic support | Yes | Yes | Yes | 4 | Yes | Yes | Yes |