A RetroSearch Logo

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

Search Query:

Showing content from http://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store below:

Atomics.store() - JavaScript | MDN

Atomics.store()

Baseline Widely available

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
语法
Atomics.store(typedArray, index, value)
参数
typedArray

一个整数类型数组。Int8Array、Uint8Array、Int16Array、Uint16Array、Int32Array、Uint32Array、BigInt64Array 或 BigUint64Array 之一。

index

typedArray 中的要存储 value 的位置。

value

要存储的数字。

返回值

已存储的值。

异常
TypeError

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

RangeError

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

示例 使用 store()
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);

Atomics.store(ta, 0, 12); // 12
规范 浏览器兼容性 参见

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