Atomics.store()

Atomics.store() 静态方法将给定的值存储在数组中的指定位置,并返回该值。

尝试一下

语法

js
Atomics.store(typedArray, index, value)

参数

typedArray

一个整数类型数组。Int8ArrayUint8ArrayInt16ArrayUint16ArrayInt32ArrayUint32ArrayBigInt64ArrayBigUint64Array (en-US) 之一。

index

typedArray 中的要存储 value 的位置。

value

要存储的数字。

返回值

已存储的值。

异常

TypeError

如果 typedArray 不是允许的整数类型数组之一,则抛出该异常。

RangeError

如果 index 超出 typedArray 的范围,则抛出该异常。

示例

使用 store()

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

Atomics.store(ta, 0, 12); // 12

规范

Specification
ECMAScript Language Specification
# sec-atomics.store

浏览器兼容性

BCD tables only load in the browser

参见