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 --- .../reference/global_objects/array/fill/index.html | 185 +++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 files/pl/web/javascript/reference/global_objects/array/fill/index.html (limited to 'files/pl/web/javascript/reference/global_objects/array/fill') diff --git a/files/pl/web/javascript/reference/global_objects/array/fill/index.html b/files/pl/web/javascript/reference/global_objects/array/fill/index.html new file mode 100644 index 0000000000..1ab2ef4719 --- /dev/null +++ b/files/pl/web/javascript/reference/global_objects/array/fill/index.html @@ -0,0 +1,185 @@ +--- +title: Array.prototype.fill() +slug: Web/JavaScript/Referencje/Obiekty/Array/fill +translation_of: Web/JavaScript/Reference/Global_Objects/Array/fill +--- +
{{JSRef}}
+ +

Metoda fill() uzupełnia wszystkie elementy tablicy, zaczynając od indeksu początkowego  (start) aż po indeks końcowy (end) statyczną wartością (value).

+ +

{{EmbedInteractiveExample("pages/js/array-fill.html")}}
+ Źródło tego przykładu jest przechowywane w repozytorium na GitHub. Jeśli chciałbyś dodać coś od siebie do projektu interaktywnych przykładów, sklonuj https://github.com/mdn/interactive-examples  i wyślij pull request.

+ +

Składnia

+ +
arr.fill(value[, start = 0[, end = this.length]])
+ +

Parametry

+ +
+
value
+
Wartość, którą wypełniana będzie tablica.
+
start
+
Opcjonalnie. Indeks początkowy.
+
end
+
Opcjonalnie. Indeks końcowy.
+
+

Wartość zwracana

+ +

Zmodyfikowana tablica.

+
+
+ +

Opis

+ +

Przedział elementów do wypełnienia to: [start, end).

+ +

Metoda fill przyjmuje do trzech parametrów value, start i end. Argumenty start i end są opcjonalne i przyjmują, odpowiednio,  0 i długość (length) obiektu this.

+ +

Jeżeli parametr start jest ujemny, jest to traktowane jako length+start gdzie length jest liczbą elementów tablicy. Jeżeli parametr end jest negatywny, jest to traktowane jako length+end

+ +

Funkcja fill została świdomie zaprojektowana jako generyczna, przez co nie wymaga, by wartość this była obiektem typu Array.

+ +

Metoda fill jest zmienna (ang. mutalbe), metoda ta nie zwraca kopii this, a oryginalny obiekt po modyfikacjach.

+ +

Przykłady

+ +
[1, 2, 3].fill(4);               // [4, 4, 4]
+[1, 2, 3].fill(4, 1);            // [1, 4, 4]
+[1, 2, 3].fill(4, 1, 2);         // [1, 4, 3]
+[1, 2, 3].fill(4, 1, 1);         // [1, 2, 3]
+[1, 2, 3].fill(4, -3, -2);       // [4, 2, 3]
+[1, 2, 3].fill(4, NaN, NaN);     // [1, 2, 3]
+[].fill.call({ length: 3 }, 4);  // {0: 4, 1: 4, 2: 4, length: 3}
+//Obiekty przez referencję
+var arr = Array(3).fill({}) // [{}, {}, {}];
+arr[0].hi = "hi"; // [{ hi: "hi" }, { hi: "hi" }, { hi: "hi" }]
+
+ +

 

+ +

 

+ +

Polyfill

+ +
if (!Array.prototype.fill) {
+  Array.prototype.fill = function(value) {
+
+    // Steps 1-2.
+    if (this == null) {
+      throw new TypeError('this is null or not defined');
+    }
+
+    var O = Object(this);
+
+    // Steps 3-5.
+    var len = O.length >>> 0;
+
+    // Steps 6-7.
+    var start = arguments[1];
+    var relativeStart = start >> 0;
+
+    // Step 8.
+    var k = relativeStart < 0 ?
+      Math.max(len + relativeStart, 0) :
+      Math.min(relativeStart, len);
+
+    // Steps 9-10.
+    var end = arguments[2];
+    var relativeEnd = end === undefined ?
+      len : end >> 0;
+
+    // Step 11.
+    var final = relativeEnd < 0 ?
+      Math.max(len + relativeEnd, 0) :
+      Math.min(relativeEnd, len);
+
+    // Step 12.
+    while (k < final) {
+      O[k] = value;
+      k++;
+    }
+
+    // Step 13.
+    return O;
+  };
+}
+
+ +

Specyfikacja

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

Kompatybilność z przeglądarkami

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FunckjonalnośćChromeFirefox (Gecko)Internet ExplorerOperaSafari
Wsparcie podstawowe{{CompatChrome("36")}} [1]{{CompatGeckoDesktop("31")}}{{CompatNo}}{{CompatNo}}{{CompatSafari("7.1")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Wsparcie podstawowe{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile("31")}}{{CompatNo}}{{CompatNo}}8.0
+
+ +

[1] The feature is available behind a preference. In chrome://flags, activate the entry “Enable Experimental JavaScript”.

+ +

Zobacz również

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