TypedArray.prototype.fill()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.
Die fill()
Methode von TypedArray
Instanzen ändert alle Elemente innerhalb eines Indexbereichs in einem typisierten Array zu einem statischen Wert. Sie gibt das modifizierte typisierte Array zurück. Diese Methode hat denselben Algorithmus wie Array.prototype.fill()
.
Probieren Sie es aus
const uint8 = new Uint8Array([0, 0, 0, 0]);
// Value, start position, end position
uint8.fill(4, 1, 3);
console.log(uint8);
// Expected output: Uint8Array [0, 4, 4, 0]
Syntax
fill(value)
fill(value, start)
fill(value, start, end)
Parameter
value
-
Wert, mit dem das typisierte Array gefüllt wird.
start
Optional-
Nullbasierter Index, ab dem das Füllen beginnt, in eine ganze Zahl umgewandelt.
end
Optional-
Nullbasierter Index, an dem das Füllen endet, in eine ganze Zahl umgewandelt.
fill()
füllt bis, aber nicht einschließlichend
.
Rückgabewert
Das modifizierte typisierte Array, gefüllt mit value
.
Beschreibung
Siehe Array.prototype.fill()
für mehr Details. Diese Methode ist nicht generisch und kann nur bei instanziierten typisierten Arrays aufgerufen werden.
Beispiele
Verwendung von fill()
new Uint8Array([1, 2, 3]).fill(4); // Uint8Array [4, 4, 4]
new Uint8Array([1, 2, 3]).fill(4, 1); // Uint8Array [1, 4, 4]
new Uint8Array([1, 2, 3]).fill(4, 1, 2); // Uint8Array [1, 4, 3]
new Uint8Array([1, 2, 3]).fill(4, 1, 1); // Uint8Array [1, 2, 3]
new Uint8Array([1, 2, 3]).fill(4, -3, -2); // Uint8Array [4, 2, 3]
Spezifikationen
Specification |
---|
ECMAScript® 2026 Language Specification # sec-%typedarray%.prototype.fill |