Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

TypedArray.prototype.fill()

BaselineWidely available

Thefill() method ofTypedArray 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 asArray.prototype.fill().

Try it

const uint8 = new Uint8Array([0, 0, 0, 0]);// Value, start position, end positionuint8.fill(4, 1, 3);console.log(uint8);// Expected output: Uint8Array [0, 4, 4, 0]

Syntax

js
fill(value)fill(value, start)fill(value, start, end)

Parameters

value

Value to fill the typed array with.

startOptional

Zero-based index at which to start filling,converted to an integer.

endOptional

Zero-based index at which to end filling,converted to an integer.fill() fills up to but not includingend.

Return value

The modified typed array, filled withvalue.

Description

SeeArray.prototype.fill() for more details. This method is not generic and can only be called on typed array instances.

Examples

Using fill()

js
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]

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-%typedarray%.prototype.fill

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp