Atomics.store()
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.store()
メソッドは、指定された値を配列内の指定した位置に格納し、その値を返します。
試してみましょう
// Create a SharedArrayBuffer with a size in bytes
const buffer = new SharedArrayBuffer(16);
const uint8 = new Uint8Array(buffer);
uint8[0] = 5;
console.log(Atomics.store(uint8, 0, 2));
// Expected output: 2
console.log(Atomics.load(uint8, 0));
// Expected output: 2
構文
js
Atomics.store(typedArray, index, value);
引数
typedArray
-
整数の型付き配列です。
Int8Array
,Uint8Array
,Int16Array
,Uint16Array
,Int32Array
,Uint32Array
の何れかです。 index
-
typedArray
でvalue
を格納する位置です。 value
-
格納する値です。
返値
格納された値です。
例外
typedArray
が許可された整数型の何れでもない場合、TypeError
が発生します。index
がtypedArray
の範囲を超えている場合、RangeError
が発生します。
例
store() の使用
js
var sab = new SharedArrayBuffer(1024);
var ta = new Uint8Array(sab);
Atomics.store(ta, 0, 12); // 12
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-atomics.store |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
store |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.