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/forEach below:

TypedArray.prototype.forEach() - JavaScript | MDN

TypedArray.prototype.forEach()

Baseline Widely available

forEach() は TypedArray インスタンスのメソッドで、型付き配列の要素ごとに一度与えられた関数を実行します。このメソッドのアルゴリズムは Array.prototype.forEach() と同じです。

試してみましょう
const uint8 = new Uint8Array([10, 20, 30]);

uint8.forEach((element) => console.log(element));

// Expected output: 10
// Expected output: 20
// Expected output: 30
構文
forEach(callbackFn)
forEach(callbackFn, thisArg)
引数
callbackFn

型付き配列のそれぞれの要素に対して実行する関数です。返値は破棄されます。この関数は以下の引数で呼び出されます。

element

現在処理されている型付き配列の要素です。

index

現在処理されている型付き配列の要素のインデックスです。

array

forEach() が呼び出されている型付き配列です。

thisArg 省略可

callbackFn を実行する際に this として使用する値。反復処理メソッドを参照してください。

返値

なし (undefined)。

解説

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

例 型付き配列の内容をログに出力する

以下のコードは型付き配列内の各要素を 1 行ずつ出力します。

function logArrayElements(element, index, array) {
  console.log(`a[${index}] = ${element}`);
}

new Uint8Array([0, 1, 2, 3]).forEach(logArrayElements);
// 出力:
// a[0] = 0
// a[1] = 1
// a[2] = 2
// a[3] = 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