diff options
author | Ryan Johnson <rjohnson@mozilla.com> | 2021-04-29 16:16:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-29 16:16:42 -0700 |
commit | 95aca4b4d8fa62815d4bd412fff1a364f842814a (patch) | |
tree | 5e57661720fe9058d5c7db637e764800b50f9060 /files/ca/web/javascript/reference/global_objects/array/every | |
parent | ee3b1c87e3c8e72ca130943eed260ad642246581 (diff) | |
download | translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.gz translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.bz2 translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.zip |
remove retired locales (#699)
Diffstat (limited to 'files/ca/web/javascript/reference/global_objects/array/every')
-rw-r--r-- | files/ca/web/javascript/reference/global_objects/array/every/index.html | 221 |
1 files changed, 0 insertions, 221 deletions
diff --git a/files/ca/web/javascript/reference/global_objects/array/every/index.html b/files/ca/web/javascript/reference/global_objects/array/every/index.html deleted file mode 100644 index cff136ba75..0000000000 --- a/files/ca/web/javascript/reference/global_objects/array/every/index.html +++ /dev/null @@ -1,221 +0,0 @@ ---- -title: Array.prototype.every() -slug: Web/JavaScript/Reference/Global_Objects/Array/every -translation_of: Web/JavaScript/Reference/Global_Objects/Array/every -original_slug: Web/JavaScript/Referencia/Objectes_globals/Array/every ---- -<div>{{JSRef}}</div> - -<p>El mètode <code><strong>every()</strong></code> comprova si tots els elements d'un array passen el test implementat per la funció proporcionada.</p> - -<h2 id="Sintaxi">Sintaxi</h2> - -<pre class="syntaxbox"><code><var>arr</var>.every(<var>callback</var>[, <var>thisArg</var>])</code></pre> - -<h3 id="Paràmetres">Paràmetres</h3> - -<dl> - <dt><code>callback</code></dt> - <dd>Funció utilitzada com a test per a cada element, rep tres arguments: - <dl> - <dt><code>valorActual</code></dt> - <dd>L'element de l'array que està sent avaluat.</dd> - <dt><code>posició</code></dt> - <dd>La posició que l'element passat al primer paràmetre ocupa dins l'array.</dd> - <dt><code>array</code></dt> - <dd>L'array des del que s'ha cridat el mètode <code>every()</code>.</dd> - </dl> - </dd> - <dt><code>thisArg</code></dt> - <dd>Opcional. Valor que valdrà la variable <code>this</code> quan s'estigui executant la funció <code>callback</code>.</dd> -</dl> - -<h2 id="Descripció">Descripció</h2> - -<p><code>every()</code> executa la funció <code>callback</code> un cop per a cada element present a l'array fins que troba un per al qual <code>callback</code> retorna un valor <em>falsy</em> (és a dir, un valor que esdebé fals si es realitza una conversió de tipus a <code>Boolean</code>). Si es troba aquest element, el mètode <code>every</code> retorna immediatament <code>false</code>. En cas contrari, si <code>callback</code> ha retornat un valor <code>true</code> per a tots els elements, <code>every</code> retornarà <code>true</code>. Només s'invocarà la funció <code>callback</code> en les posicions de l'array que tinguin un valor assignat, és a dir, mai es cridarà per a posicions que han estat esborrades o el valor de les quals no ha estat mai assignat.</p> - -<p>S'invoca <code>callback</code> amb tres arguments: el valor de l'element, la posició de l'element dins l'array, i l'objecte array que es recorrerà.</p> - -<p>Si es proporciona el paràmetre <code>thisArg</code> al mètode <code>every()</code>, aquest es passarà a <code>callback</code> quan s'invoqui, i serà el valor que mostrarà la variable <code>this</code>. En cas contrari, s'utilitzarà el valor <a href="https://developer.mozilla.org/ca/docs/Web/JavaScript/Referencia/Objectes_globals/undefined" title="El valor de la propietat global undefined representa el valor undefined. És un dels tipus primitius de JavaScript."><code>undefined</code></a> com a valor per a <code>this</code>. El valor de <code>this</code> observable en última instància per <code>callback</code> es determinarà d'acord a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this">les regles per a determinar el valor de <code>this</code> observat per una funció</a>.</p> - -<p><code>every()</code> no mutarà l'array quan sigui cridada.</p> - -<p>El rang d'elements processat per <code>every()</code> és determinat abans de la primera invocació de <code>callback</code>. Els elements que s'afegeixin a l'array després de la crida a <code>every()</code> no seran visitats per <code>callback</code>. Si el valor d'un element encara no visitat canvia, el valor que es passarà a <code>callback</code> serà el valor que tingui aquest element a l'hora de visitar-lo; els elements que s'esborrin no es visitaran.</p> - -<p><code>every</code> es comporta com un quantificador "for all" en matemàtiques. En concret, per a un array buit retornarà <code>true</code> (s'anomena <a href="http://en.wikipedia.org/wiki/Vacuous_truth#Vacuous_truths_in_mathematics">veritat per buit</a> el fet que tots els elements d'un <a href="http://en.wikipedia.org/wiki/Empty_set#Common_problems">grup buit</a> satisfacin qualsevol condició donada).</p> - -<h2 id="Exemples">Exemples</h2> - -<h3 id="Comprovar_el_tamany_de_tots_els_elements_d'un_array">Comprovar el tamany de tots els elements d'un array</h3> - -<p>L'exemple següent comprova si tots els elements d'un array son majors de 10.</p> - -<pre class="brush: js">function isBigEnough(element, index, array) { - return element >= 10; -} -[12, 5, 8, 130, 44].every(isBigEnough); // false -[12, 54, 18, 130, 44].every(isBigEnough); // true -</pre> - -<h3 id="Utilitzar_funcions_flexta">Utilitzar funcions flexta</h3> - -<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">Les funcions fletxa</a> ofereixen una sintaxi reduïda per a realitzar el mateix test.</p> - -<pre class="brush: js">[12, 5, 8, 130, 44].every(elem => elem >= 10); // false -[12, 54, 18, 130, 44].every(elem => elem >= 10); // true</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<p><code>every</code> va ser afegida al standard ECMA-262 en la cinquena edició; és per això que pot no estar disponible en certes implementacions del standard. Es pot proporcionar la seva funcionalitat inserint l'script següent a l'inici dels vostres scripts, permetent l'ús de <code>every()</code> en implementacions que no la suporten de forma nativa. Aquest algoritme és exactament l'especificat a l'ECMA-262, cinquena edició, assumint que <a class="new" href="https://developer.mozilla.org/ca/docs/Web/JavaScript/Referencia/Object" title="Aquesta pàgina encara no ha estat traduïda. Si us plau considera contribuir-hi!"><code>Object</code></a> i <a href="https://developer.mozilla.org/ca/docs/Web/JavaScript/Referencia/Objectes_globals/TypeError" title="L'objecte TypeError representa un error quan el valor no és del tipus esperat."><code>TypeError</code></a> tenen els valors originals i que <code>callbackfn.call</code> es correspon amb el valor original de {{jsxref("Function.prototype.call")}}.</p> - -<pre class="brush: js">if (!Array.prototype.every) { - Array.prototype.every = function(callbackfn, thisArg) { - 'use strict'; - var T, k; - - if (this == null) { - throw new TypeError('this is null or not defined'); - } - - // 1. Let O be the result of calling ToObject passing the this - // value as the argument. - var O = Object(this); - - // 2. Let lenValue be the result of calling the Get internal method - // of O with the argument "length". - // 3. Let len be ToUint32(lenValue). - var len = O.length >>> 0; - - // 4. If IsCallable(callbackfn) is false, throw a TypeError exception. - if (typeof callbackfn !== 'function') { - throw new TypeError(); - } - - // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. - if (arguments.length > 1) { - T = thisArg; - } - - // 6. Let k be 0. - k = 0; - - // 7. Repeat, while k < len - while (k < len) { - - var kValue; - - // a. Let Pk be ToString(k). - // This is implicit for LHS operands of the in operator - // b. Let kPresent be the result of calling the HasProperty internal - // method of O with argument Pk. - // This step can be combined with c - // c. If kPresent is true, then - if (k in O) { - - // i. Let kValue be the result of calling the Get internal method - // of O with argument Pk. - kValue = O[k]; - - // ii. Let testResult be the result of calling the Call internal method - // of callbackfn with T as the this value and argument list - // containing kValue, k, and O. - var testResult = callbackfn.call(T, kValue, k, O); - - // iii. If ToBoolean(testResult) is false, return false. - if (!testResult) { - return false; - } - } - k++; - } - return true; - }; -} -</pre> - -<h2 id="Especificacions">Especificacions</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Especificaicó</th> - <th scope="col">Estat</th> - <th scope="col">Comentaris</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.4.4.16', 'Array.prototype.every')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Definició inicial. Implemnetat a JavaScript 1.6.</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.prototype.every', 'Array.prototype.every')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.every', 'Array.prototype.every')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> - -<div>{{CompatibilityTable}}</div> - -<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>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoDesktop("1.8")}}</td> - <td>{{CompatIE("9")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</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>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoMobile("1.8")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="Vegeu_també">Vegeu també</h2> - -<ul> - <li>{{jsxref("Array.prototype.forEach()")}}</li> - <li>{{jsxref("Array.prototype.some()")}}</li> - <li>{{jsxref("TypedArray.prototype.every()")}}</li> -</ul> |