A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill below:

TypedArray.prototype.fill() - JavaScript | MDN

TypedArray.prototype.fill()

Baseline Widely available

fill() は TypedArray インスタンスのメソッドで、型付き配列のある範囲のインデックスにあるすべての要素を固定値で埋めます。これは変更された型付き配列を返します。このメソッドのアルゴリズムは 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)
引数
value

型付き配列を埋める値です。

start 省略可

埋まる範囲の開始点を表すゼロ基点のインデックスで、整数に変換されます。

end 省略可

埋まる範囲の終了点を表すゼロ基点のインデックスで、整数に変換されます。 fill() は end の手前までを埋めます。

返値

変更された配列です。

解説

詳細については、 Array.prototype.fill() をご覧ください。このメソッドは汎用的ではなく、型付き配列インスタンスに対してのみ呼び出すことができます。

例 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]
仕様書 ブラウザーの互換性 関連情報

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4