| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since September 2016.
The fill() method of TypedArray instances changes all elements within a range of indices in a typed array to a static value. It returns the modified typed array. This method has the same algorithm as Array.prototype.fill().
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]
fill(value)
fill(value, start)
fill(value, start, end)
valueValue to fill the typed array with.
start OptionalZero-based index at which to start filling, converted to an integer.
end OptionalZero-based index at which to end filling, converted to an integer. fill() fills up to but not including end.
The modified typed array, filled with value.
See Array.prototype.fill() for more details. This method is not generic and can only be called on typed array instances.
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]
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-%typedarray%.prototype.fill |
TypedArray.prototype.fill in core-jsTypedArrayArray.prototype.fill()This page was last modified on Jul 10, 2025 by MDN contributors.
TypedArrayObject/FunctionBigInt64ArrayBigUint64ArrayFloat16ArrayFloat32ArrayFloat64ArrayInt8ArrayInt16ArrayInt32ArrayUint8ArrayUint8ClampedArrayUint16ArrayUint32ArrayYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |