aboutsummaryrefslogtreecommitdiff
path: root/files/it/web/api/nodelist/foreach/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/it/web/api/nodelist/foreach/index.html')
-rw-r--r--files/it/web/api/nodelist/foreach/index.html125
1 files changed, 125 insertions, 0 deletions
diff --git a/files/it/web/api/nodelist/foreach/index.html b/files/it/web/api/nodelist/foreach/index.html
new file mode 100644
index 0000000000..5d8f5d0088
--- /dev/null
+++ b/files/it/web/api/nodelist/foreach/index.html
@@ -0,0 +1,125 @@
+---
+title: NodeList.prototype.forEach()
+slug: Web/API/NodeList/forEach
+tags:
+ - DOM
+ - Iterabile
+ - NodeList
+ - Referenza
+ - Web
+ - metodo
+translation_of: Web/API/NodeList/forEach
+---
+<p>{{APIRef("DOM")}}</p>
+
+<p>Il metodo <strong><code>forEach()</code></strong> dell'interfaccia {{domxref("NodeList")}} chiama il callback fornito nel parametro una volta per ogni coppia di valori nell'elenco, in ordine di inserimento.</p>
+
+<h2 id="Sintassi">Sintassi</h2>
+
+<pre class="syntaxbox"><em>NodeList.</em>forEach<em>(callback[, thisArg]);</em>
+</pre>
+
+<h3 id="Parametri">Parametri</h3>
+
+<dl>
+ <dt><code>callback</code></dt>
+ <dd>Funzione da eseguire per ciascun elemento, eventualmente con 3 argomenti:
+ <dl>
+ <dt><em><code>currentValue</code></em></dt>
+ <dd>L'elemento corrente in elaborazione nella NodeList.</dd>
+ <dt><code><em>currentIndex</em></code></dt>
+ <dd>L'indice dell'elemento corrente in fase di elaborazione nella NodeList.</dd>
+ <dt><em><code>listObj</code></em></dt>
+ <dd>La NodeList a cui viene applicato <code>forEach()</code>.</dd>
+ </dl>
+ </dd>
+ <dt><code>thisArg</code><code> {{Optional_inline}}</code></dt>
+ <dd>Valore da utilizzare come {{jsxref("this")}} quando viene eseguito <code>callback</code>.</dd>
+</dl>
+
+<h3 id="Valore_di_ritorno">Valore di ritorno</h3>
+
+<p>{{jsxref('undefined')}}.</p>
+
+<h2 id="Eccezioni">Eccezioni</h2>
+
+<p><em>Nessuna</em>.</p>
+
+<h2 id="Esempio">Esempio</h2>
+
+<pre class="brush: js;highlight:[6]">var node = document.createElement("div");
+var kid1 = document.createElement("p");
+var kid2 = document.createTextNode("hey");
+var kid3 = document.createElement("span");
+
+node.appendChild(kid1);
+node.appendChild(kid2);
+node.appendChild(kid3);
+
+var list = node.childNodes;
+
+list.forEach(
+ function(currentValue, currentIndex, listObj) {
+ console.log(currentValue + ', ' + currentIndex + ', ' + this);
+ },
+ 'myThisArg'
+);</pre>
+
+<p>ritorna:</p>
+
+<pre>[object HTMLParagraphElement], 0, myThisArg
+[object Text], 1, myThisArg
+[object HTMLSpanElement], 2, myThisArg</pre>
+
+<h2 id="Polyfill">Polyfill</h2>
+
+<p>Questo {{Glossary("Polyfill","polyfill")}} aggiunge compatibilità a tutti i browser che supportano <a href="https://caniuse.com/#search=es5">ES5</a>:</p>
+
+<pre class="brush: js">if (window.NodeList &amp;&amp; !NodeList.prototype.forEach) {
+  NodeList.prototype.forEach = function (callback, thisArg) {
+ thisArg = thisArg || window;
+  for (var i = 0; i &lt; this.length; i++) {
+  callback.call(thisArg, this[i], i, this);
+  }
+ };
+}</pre>
+
+<p>OPPURE</p>
+
+<pre class="brush: js">if (window.NodeList &amp;&amp; !NodeList.prototype.forEach) {
+  NodeList.prototype.forEach = Array.prototype.forEach;
+}</pre>
+
+<p>Il comportamento sopra riportato indica il numero di browser che implementa effettivamente NodeList.prototype.forEach (Chrome, ad esempio).</p>
+
+<h2 id="Specifiche">Specifiche</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specifica</th>
+ <th scope="col">Stato</th>
+ <th scope="col">Commento</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName("WebIDL", "#es-forEach", "forEach")}}</td>
+ <td>{{Spec2("WebIDL")}}</td>
+ <td>Definisce <code>forEach</code> sulle dichiarazioni <code>iterable</code></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilità_con_i_browser">Compatibilità con i browser</h2>
+
+
+
+<p>{{Compat("api.NodeList.forEach")}}</p>
+
+<h2 id="Vedi_anche">Vedi anche</h2>
+
+<ul>
+ <li>{{domxref("Node")}}</li>
+ <li>{{domxref("NodeList")}}</li>
+</ul>