aboutsummaryrefslogtreecommitdiff
path: root/files/ca/web/javascript/referencia/objectes_globals/array/includes
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:41:15 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:41:15 -0500
commit4b1a9203c547c019fc5398082ae19a3f3d4c3efe (patch)
treed4a40e13ceeb9f85479605110a76e7a4d5f3b56b /files/ca/web/javascript/referencia/objectes_globals/array/includes
parent33058f2b292b3a581333bdfb21b8f671898c5060 (diff)
downloadtranslated-content-4b1a9203c547c019fc5398082ae19a3f3d4c3efe.tar.gz
translated-content-4b1a9203c547c019fc5398082ae19a3f3d4c3efe.tar.bz2
translated-content-4b1a9203c547c019fc5398082ae19a3f3d4c3efe.zip
initial commit
Diffstat (limited to 'files/ca/web/javascript/referencia/objectes_globals/array/includes')
-rw-r--r--files/ca/web/javascript/referencia/objectes_globals/array/includes/index.html158
1 files changed, 158 insertions, 0 deletions
diff --git a/files/ca/web/javascript/referencia/objectes_globals/array/includes/index.html b/files/ca/web/javascript/referencia/objectes_globals/array/includes/index.html
new file mode 100644
index 0000000000..9f64b0e117
--- /dev/null
+++ b/files/ca/web/javascript/referencia/objectes_globals/array/includes/index.html
@@ -0,0 +1,158 @@
+---
+title: Array.prototype.includes()
+slug: Web/JavaScript/Referencia/Objectes_globals/Array/includes
+translation_of: Web/JavaScript/Reference/Global_Objects/Array/includes
+---
+<div>{{JSRef}}</div>
+
+<p>El mètode <code><strong>includes()</strong></code> determina si un array inclou un element concret, retornant  <code>true</code> o <code>false</code> segons s'escaigui. </p>
+
+<h2 id="Sintaxi">Sintaxi</h2>
+
+<pre class="syntaxbox">var <var>boolean</var> = <var>array</var>.includes(elementCercat[, desdePosicio])</pre>
+
+<h3 id="Parameters">Parameters</h3>
+
+<dl>
+ <dt>elementCercat</dt>
+ <dd>L'element a cercar.</dd>
+ <dt>desdePosicio</dt>
+ <dd>Opcional. La posició de l'array a partir de la qual començar la cerca de <code>elementCercat</code>. Un valor negatiu cercarà el nombre absolut donat de posicions contant des del final de l'array. El seu valor per defecte és 0.</dd>
+</dl>
+
+<h3 id="Valor_retornat">Valor retornat</h3>
+
+<p>Un {{jsxref("Boolean")}}.</p>
+
+<h2 id="Exemples">Exemples</h2>
+
+<pre class="brush: js">[1, 2, 3].includes(2); // true
+[1, 2, 3].includes(4); // false
+[1, 2, 3].includes(3, 3); // false
+[1, 2, 3].includes(3, -1); // true
+[1, 2, NaN].includes(NaN); // true
+</pre>
+
+<h2 id="Polyfill">Polyfill</h2>
+
+<pre class="brush: js">if (!Array.prototype.includes) {
+  Array.prototype.includes = function(searchElement /*, fromIndex*/ ) {
+  'use strict';
+    var O = Object(this);
+    var len = parseInt(O.length) || 0;
+    if (len === 0) {
+      return false;
+    }
+    var n = parseInt(arguments[1]) || 0;
+    var k;
+    if (n &gt;= 0) {
+      k = n;
+    } else {
+      k = len + n;
+      if (k &lt; 0) {k = 0;}
+    }
+    var currentElement;
+    while (k &lt; len) {
+      currentElement = O[k];
+      if (searchElement === currentElement ||
+         (searchElement !== searchElement &amp;&amp; currentElement !== currentElement)) { // NaN !== NaN
+        return true;
+      }
+      k++;
+    }
+    return false;
+  };
+}
+</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('ES7', '#sec-array.prototype.includes', 'Array.prototype.includes')}}</td>
+ <td>{{Spec2('ES7')}}</td>
+ <td>Definició inicial.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-array.prototype.includes', 'Array.prototype.includes')}}</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>Edge</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Suport bàsic</td>
+ <td>
+ <p>{{CompatChrome(47)}}</p>
+ </td>
+ <td>43</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>34</td>
+ <td>9</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Característica</th>
+ <th>Android</th>
+ <th>Android Webview</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ <th>Chrome for Android</th>
+ </tr>
+ <tr>
+ <td>Suport bàsic</td>
+ <td>{{CompatNo}}</td>
+ <td>
+ <p>{{CompatChrome(47)}}</p>
+ </td>
+ <td>43</td>
+ <td>{{CompatNo}}</td>
+ <td>34</td>
+ <td>9</td>
+ <td>
+ <p>{{CompatChrome(47)}}</p>
+ </td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="Vegeu_també">Vegeu també</h2>
+
+<ul>
+ <li>{{jsxref("TypedArray.prototype.includes()")}}</li>
+ <li>{{jsxref("String.prototype.includes()")}}</li>
+ <li>{{jsxref("Array.prototype.indexOf()")}}</li>
+</ul>