diff options
Diffstat (limited to 'files/ca/web/javascript/reference/global_objects/map/foreach')
| -rw-r--r-- | files/ca/web/javascript/reference/global_objects/map/foreach/index.html | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/files/ca/web/javascript/reference/global_objects/map/foreach/index.html b/files/ca/web/javascript/reference/global_objects/map/foreach/index.html deleted file mode 100644 index 16a6625eb6..0000000000 --- a/files/ca/web/javascript/reference/global_objects/map/foreach/index.html +++ /dev/null @@ -1,137 +0,0 @@ ---- -title: Map.prototype.forEach() -slug: Web/JavaScript/Reference/Global_Objects/Map/forEach -translation_of: Web/JavaScript/Reference/Global_Objects/Map/forEach -original_slug: Web/JavaScript/Referencia/Objectes_globals/Map/forEach ---- -<div>{{JSRef}}</div> - -<p>El mètode <code><strong>forEach()</strong></code> executa la funció proporcionada un cop epr cada parell clau/valor dins l'objecte <code>Map</code>, seguint l'ordre en el que han estat inserits.</p> - -<h2 id="Sintaxi">Sintaxi</h2> - -<pre class="syntaxbox"><code><em>myMap</em>.forEach(<em>callback</em>[, <em>thisArg</em>])</code></pre> - -<h3 id="Paràmetres">Paràmetres</h3> - -<dl> - <dt><code>callback</code></dt> - <dd>Funció a executar per a cada element.</dd> - <dt><code>thisArg</code></dt> - <dd>Valor a utilitzar com a <code>this</code> mentre s'estigui executant executing <code>callback</code>.</dd> -</dl> - -<h2 id="Descripció">Descripció</h2> - -<p>El mètode <code>forEach</code> executa la funció <code>callback</code> proporcionada un cop per a cada clau que existeixi dins el mapa. No s'invocarà la funció per a claus que hagin estat esborrades. Tanmateix si que s'executarà per a valors amb clau present però que el seu valor sigui <code>undefined</code>.</p> - -<p><code>callback</code> s'invocarà amb <strong>tres</strong><strong> arguments</strong>:</p> - -<ul> - <li>el <strong>valor de l'element</strong></li> - <li>la <strong>clau de l'element</strong></li> - <li>l'<strong>objecte </strong><strong><code>Map</code> que s'està recorrent</strong></li> -</ul> - -<p>Si es proporciona el paràmetre <code>thisArg</code> a la crida de <code>forEach</code>, aquest es passarà a <code>callback</code> quan s'invoqui per a ser utilitzat com a <code>this</code> dins la funció. En qualsevol altre cas el valor que rebrà <code>this</code> dins la funció <code>callback</code> serà <code>undefined</code>. El valor de <code>this</code> que serà finalment observable dins de <code>callback</code> és determinat d'acord a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this">les regles habituals per a determinar el valor de <code>this</code> observat dins d'una funció</a>.</p> - -<p>Cada valor serà visitat un cop, a no ser que hagi estat eliminat o tornar a afegir abans que el mètode <code>forEach</code> acabi. No s'invocarà <code>callback</code> per a valors eliminats abans de ser visitats. Si que es visitaran, però, valors nous afegits abans <code>forEach</code> no hagi acabat.</p> - -<p><code>forEach</code> executa la funció <code>callback</code> un cop per cada element de l'objecte <code>Map</code>; no retorna cap valor.</p> - -<h2 id="Exemples">Exemples</h2> - -<h3 id="Mostrar_els_continguts_d'un_objecte_Map">Mostrar els continguts d'un objecte <code>Map</code></h3> - -<p>El codi següent mostra una línia per cada element d'un objecte <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); -// mostra: -// "m[foo] = 3" -// "m[bar] = [object Object]" -// "m[baz] = undefined" -</pre> - -<h2 id="Especificacions">Especificacions</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Especificació</th> - <th scope="col">Estat</th> - <th scope="col">Comentaris</th> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-map.prototype.foreach', 'Map.prototype.forEach')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>Definició inicial.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-map.prototype.foreach', 'Map.prototype.forEach')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> - -<p>{{CompatibilityTable}}</p> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Característica</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Suport bàsic</td> - <td>38</td> - <td>{{CompatGeckoDesktop("25.0")}}</td> - <td>11</td> - <td>25</td> - <td>7.1</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Característica</th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Suport bàsic</td> - <td>{{CompatNo}}</td> - <td>38</td> - <td>{{CompatGeckoMobile("25.0")}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>8</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="Vegeu_també">Vegeu també</h2> - -<ul> - <li>{{jsxref("Array.prototype.forEach()")}}</li> - <li>{{jsxref("Set.prototype.forEach()")}}</li> -</ul> |
