diff options
Diffstat (limited to 'files/it/web/javascript/reference/global_objects/array/join')
-rw-r--r-- | files/it/web/javascript/reference/global_objects/array/join/index.html | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/files/it/web/javascript/reference/global_objects/array/join/index.html b/files/it/web/javascript/reference/global_objects/array/join/index.html new file mode 100644 index 0000000000..8483c817ac --- /dev/null +++ b/files/it/web/javascript/reference/global_objects/array/join/index.html @@ -0,0 +1,112 @@ +--- +title: Array.prototype.join() +slug: Web/JavaScript/Reference/Global_Objects/Array/join +tags: + - Array + - JavaScript + - Prototype + - Referenza + - metodo +translation_of: Web/JavaScript/Reference/Global_Objects/Array/join +--- +<div>{{JSRef}}</div> + +<p>Il metodo <code><strong>join()</strong></code> unisce tutti gli elementi di un array (o di un <a href="/en-US/docs/Web/JavaScript/Guide/Indexed_collections#Working_with_array-like_objects">array di </a>oggetti) in una stringa che viene restituita.</p> + +<pre class="brush: js">var a = ['Wind', 'Rain', 'Fire']; +a.join(); // 'Wind,Rain,Fire' +a.join('-'); // 'Wind-Rain-Fire'</pre> + +<h2 id="Sintassi">Sintassi</h2> + +<pre class="syntaxbox"><var>arr</var>.join() +<var>arr</var>.join(<var>separatore</var>)</pre> + +<h3 id="Parametri">Parametri</h3> + +<dl> + <dt><code>separatore</code> {{optional_inline}}</dt> + <dd>Specifica una stringa che separa ogni coppia di elementi adiacenti dell'array. Il separatore è trasformato in una stringa, se necessario. Se omesso, gli elementi dell'array saranno separati da una virgola (","). Se il <code>separatore</code> è una stringa vuota, tutti gli elementi sono uniti senza alcun carattere intemedio.</dd> +</dl> + +<h3 id="Valore_di_risposta">Valore di risposta</h3> + +<p>Una stringa con tutti con tutti gli elementi dell'array uniti. Se <code><em>arr</em>.length</code> è <code>0</code>, viene restituita una stringa vuota.</p> + +<h2 id="Descrizione">Descrizione</h2> + +<p>Le stringe ottenute dalla conversione di tutti gli elementi dell'array sono unite in un unica stringa.</p> + +<div class="warning"> +<p>Se un elemento è <code>undefined</code> o <code>null</code>, sarà convertito in una stringa vuota.</p> +</div> + +<h2 id="Esempi">Esempi</h2> + +<h3 id="Quattro_modi_per_concatenare_un_array">Quattro modi per concatenare un array</h3> + +<p>Il seguente esempio crea un array, <code>a</code>, con tre elementi, quindi unisce gli elementi dell'array quattro volte: usando l'operatore di default, poi una virgola e uno spazio, poi un più e infine una stringa vuota.</p> + +<pre class="brush: js">var a = ['Wind', 'Rain', 'Fire']; +a.join(); // 'Wind,Rain,Fire' +a.join(', '); // 'Wind, Rain, Fire' +a.join(' + '); // 'Wind + Rain + Fire' +a.join(''); // 'WindRainFire'</pre> + +<h3 id="Unione_di_un_oggetto_di_tipo_array">Unione di un oggetto di tipo array</h3> + +<p>Il seguente esempio unisce un oggetto di tipo array (<code><a href="/en-US/docs/Web/JavaScript/Reference/Functions/arguments">arguments</a></code>), chiamando {{jsxref("Function.prototype.call")}} con <code>Array.prototype.join</code>.</p> + +<pre class="brush: js">function f(a, b, c) { + var s = Array.prototype.join.call(arguments); + console.log(s); // '<span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body"><span class="objectBox objectBox-string">1,a,true'</span></span></span></span> +} +f(1, 'a', true);</pre> + +<h2 id="Specifiche">Specifiche</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specifiche</th> + <th scope="col">Stato</th> + <th scope="col">Commenti</th> + </tr> + <tr> + <td>{{SpecName('ES1')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Definizione iniziale. Implementato in JavaScript 1.1.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.4.4.5', 'Array.prototype.join')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-array.prototype.join', 'Array.prototype.join')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-array.prototype.join', 'Array.prototype.join')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilità_browser">Compatibilità browser</h2> + +<div> + + +<p>{{Compat("javascript.builtins.Array.join")}}</p> +</div> + +<h2 id="Guarda_anche">Guarda anche</h2> + +<ul> + <li>{{jsxref("String.prototype.split()")}}</li> + <li>{{jsxref("Array.prototype.toString()")}}</li> + <li>{{jsxref("TypedArray.prototype.join()")}}</li> +</ul> |