Atomics.load()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since December 2021.

静的な Atomics.load() メソッドは、配列内の指定された位置の値を返します。

試してみましょう

// Create a SharedArrayBuffer with a size in bytes
const buffer = new SharedArrayBuffer(16);
const uint8 = new Uint8Array(buffer);
uint8[0] = 5;

// 5 + 2 = 7
console.log(Atomics.add(uint8, 0, 2));
// Expected output: 5

console.log(Atomics.load(uint8, 0));
// Expected output: 7

構文

js
Atomics.load(typedArray, index);

引数

typedArray

整数の型付き配列です。 Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array の何れかです。

index

typedArray の中で値を読み込む位置。

返値

指定された位置 (typedArray[index]) にある値です。

例外

  • typedArray が許可された整数型の何れでもない場合、TypeError が発生します。
  • indextypedArray の範囲を超えている場合、 RangeError が発生します。

load の使用

js
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);

Atomics.add(ta, 0, 12);
Atomics.load(ta, 0); // 12

仕様書

Specification
ECMAScript® 2025 Language Specification
# sec-atomics.load

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
load

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報