From de5c456ebded0e038adbf23db34cc290c8829180 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:49:24 +0100 Subject: unslug pl: move --- .../global_objects/array/includes/index.html | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 files/pl/web/javascript/reference/global_objects/array/includes/index.html (limited to 'files/pl/web/javascript/reference/global_objects/array/includes') diff --git a/files/pl/web/javascript/reference/global_objects/array/includes/index.html b/files/pl/web/javascript/reference/global_objects/array/includes/index.html new file mode 100644 index 0000000000..526e660571 --- /dev/null +++ b/files/pl/web/javascript/reference/global_objects/array/includes/index.html @@ -0,0 +1,110 @@ +--- +title: Array.prototype.includes() +slug: Web/JavaScript/Referencje/Obiekty/Array/includes +translation_of: Web/JavaScript/Reference/Global_Objects/Array/includes +--- +
{{JSRef}}
+ +

Metoda includes() ustala czy dana tablica posiada szukany element, zwracając true lub false.

+ +

Składnia

+ +
var boolean = array.includes(searchElement[, fromIndex])
+ +

Zwraca

+ +

{{jsxref("Boolean")}}.

+ +

Parametry

+ +
+
searchElement
+
Szukany element.
+
fromIndex
+
Opcjonalne. Jest to pozycja w tablicy, od której rozpoczyna się szukanie elementu searchElement. Ujemna wartość przeszukuje tablicę od końca tablicy. Domyślna wartość wynosi 0.
+
+ +

Przykłady

+ +
[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
+
+ +

Polyfill

+ +
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 >= 0) {
+      k = n;
+    } else {
+      k = len + n;
+      if (k < 0) {k = 0;}
+    }
+    var currentElement;
+    while (k < len) {
+      currentElement = O[k];
+      if (searchElement === currentElement ||
+         (searchElement !== searchElement && currentElement !== currentElement)) { // NaN !== NaN
+        return true;
+      }
+      k++;
+    }
+    return false;
+  };
+}
+
+ +

Specyfikacja

+ + + + + + + + + + + + + + + + + + + +
SpecyfikacjaStatusKomentarz
{{SpecName('ES7', '#sec-array.prototype.includes', 'Array.prototype.includes')}}{{Spec2('ES7')}}Definicja początkowa.
{{SpecName('ESDraft', '#sec-array.prototype.includes', 'Array.prototype.includes')}}{{Spec2('ESDraft')}} +

 

+
+ +

Kompatybilność przeglądarek

+ +
+
+ + +

{{Compat("javascript.builtins.Array.includes")}}

+
+
+ +

Zobacz również

+ + -- cgit v1.2.3-54-g00ecf