diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:17 -0500 |
| commit | da78a9e329e272dedb2400b79a3bdeebff387d47 (patch) | |
| tree | e6ef8aa7c43556f55ddfe031a01cf0a8fa271bfe /files/it/web/javascript/reference/global_objects/map/foreach | |
| parent | 1109132f09d75da9a28b649c7677bb6ce07c40c0 (diff) | |
| download | translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.gz translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.bz2 translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.zip | |
initial commit
Diffstat (limited to 'files/it/web/javascript/reference/global_objects/map/foreach')
| -rw-r--r-- | files/it/web/javascript/reference/global_objects/map/foreach/index.html | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/files/it/web/javascript/reference/global_objects/map/foreach/index.html b/files/it/web/javascript/reference/global_objects/map/foreach/index.html new file mode 100644 index 0000000000..ab1c69a310 --- /dev/null +++ b/files/it/web/javascript/reference/global_objects/map/foreach/index.html @@ -0,0 +1,88 @@ +--- +title: Map.prototype.forEach() +slug: Web/JavaScript/Reference/Global_Objects/Map/forEach +tags: + - ECMAScript 2015 + - JavaScript + - Map + - metodo +translation_of: Web/JavaScript/Reference/Global_Objects/Map/forEach +--- +<div>{{JSRef}}</div> + +<p>Il metodo <code><strong>forEach() </strong></code>esegue una funzione fornita come argomento una volta per ogni coppia <code>key/value</code> nell'oggetto <code>Map</code>, secondo l'ordine dell'inseriemento dei valori.</p> + +<h2 id="Sintassi">Sintassi</h2> + +<pre class="syntaxbox"><code><em>myMap</em>.forEach(<em>callback</em>[, <em>thisArg</em>])</code></pre> + +<h3 id="Parametri">Parametri</h3> + +<dl> + <dt><code>callback</code></dt> + <dd>Funzione da eseguire per ogni elemento.</dd> + <dt><code>thisArg</code></dt> + <dd>Valore da usare come <code>this</code> quando si esegue <code>callback</code>.</dd> +</dl> + +<h2 id="Descrizione">Descrizione</h2> + +<p>Il metodo <code>forEach</code> esegue il <code>callback</code> passato come parametro una volta per ogni <em>key</em> della <em>map</em> esistente. Non è invocato per <em>key</em> che sono state cancellate. Comunque, è invocato per valori che sono presenti ma hanno valore <code>undefined</code>.</p> + +<p><code>callback </code>è invocato con <strong>tre argomenti</strong><code>:</code></p> + +<ul> + <li>il <strong>valore</strong> dell'<strong>elemento</strong></li> + <li>la <strong>chiave</strong> dell'<strong>elemento</strong></li> + <li>l'oggetto <strong><code>Map</code> </strong>su cui si sta eseguendo il ciclo</li> +</ul> + +<p>Se il parametro <code>thisArg</code> è fornito al <code>forEach</code>, sarà passato al <code>callback</code> quando viene invocato, per essere usato come suo valore <code>this</code>. In caso contrario, sarà passato il valore <code>undefined</code> per essere usato come valore <code>this</code>. Il valore <code>this </code>visibile definitivamente dal <code>callback</code>è determinato secondo le <a href="/en-US/docs/Web/JavaScript/Reference/Operators/this">normali regole per determinare il this visibile da una funzione</a>.</p> + +<p>Il range di elementi processati da <code>forEach</code> è determinato anteriormente alla prima invocazione del <code>callback</code>. Gli elementi che sono aggiunti all'oggetto <code>Map</code> dopo che la chiamata a <code>forEach</code> inizi non saranno visitati dal <code>callback</code>. Se eleemnti esistenti dell'oggetto <code>Map</code> vengono cambiati, o cancellati, il loro valore passato al <code>callback</code> sarà il valore nel momento in cui il <code>forEach</code> li visita; elementi che vengono cancellati non sono visitati.</p> + +<p><code>forEach</code> esegue la funzione <code>callback</code> una volta per ogni elemento nell'oggetto <code>Map</code>; non restituisce alcun valore.</p> + +<h2 id="Esempi">Esempi</h2> + +<h3 id="Stampare_il_contenuto_di_un_oggetto_Map"><code>Stampare il contenuto di un oggetto Map</code></h3> + +<p>Il seguente codice stampa nella console una riga per ogni elemento in un oggetto<code> Map</code>:</p> + +<pre class="brush:js">function logMapElements(value, key, map) { + console.log("m[" + key + "] = " + value); +} +Map([["foo", 3], ["bar", {}], ["baz", undefined]]).forEach(logMapElements); +// logs: +// "m[foo] = 3" +// "m[bar] = [object Object]" +// "m[baz] = undefined" +</pre> + +<h2 id="Specifiche">Specifiche</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Stato</th> + <th scope="col">Commento</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-map.prototype.foreach', 'Map.prototype.forEach')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Definizione iniziale.</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilità_dei_browser">Compatibilità dei browser</h2> + +<p>{{Compat("javascript.builtins.Map.forEach")}}</p> + +<h2 id="Vedi_anche">Vedi anche</h2> + +<ul> + <li>{{jsxref("Array.prototype.forEach()")}}</li> + <li>{{jsxref("Set.prototype.forEach()")}}</li> +</ul> |
