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.

Die statische Methode Atomics.store() speichert einen angegebenen Wert an einer angegebenen Position im Array und gibt diesen Wert zurück.

Probieren Sie es aus

// 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

Syntax

js
Atomics.store(typedArray, index, value)

Parameter

typedArray

Ein Integer-Typed-Array. Eines von Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array oder BigUint64Array.

index

Die Position im typedArray, an der der value gespeichert wird.

value

Die Zahl, die gespeichert werden soll.

Rückgabewert

Der Wert, der gespeichert wurde.

Ausnahmen

TypeError

Wird ausgelöst, wenn typedArray nicht einer der erlaubten Integer-Typen ist.

RangeError

Wird ausgelöst, wenn index im typedArray außerhalb des gültigen Bereichs liegt.

Beispiele

Verwendung von store()

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

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

Spezifikationen

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

Browser-Kompatibilität

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
store

Legend

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

Full support
Full support

Siehe auch