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.
Please help us by answering a few questions.
Die statische Methode Atomics.load()
gibt einen Wert an einer bestimmten Position im Array 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;
// 5 + 2 = 7
console.log(Atomics.add(uint8, 0, 2));
// Expected output: 5
console.log(Atomics.load(uint8, 0));
// Expected output: 7
Syntax
Atomics.load(typedArray, index)
Parameter
typedArray
-
Ein ganzzahliges getyptes Array. Eines von
Int8Array
,Uint8Array
,Int16Array
,Uint16Array
,Int32Array
,Uint32Array
,BigInt64Array
oderBigUint64Array
. index
-
Die Position innerhalb des
typedArray
, von der geladen wird.
Rückgabewert
Der Wert an der angegebenen Position (typedArray[index]
).
Ausnahmen
TypeError
-
Wird ausgelöst, wenn
typedArray
nicht einer der erlaubten ganzzahligen Typen ist. RangeError
-
Wird ausgelöst, wenn
index
außerhalb der Grenzen destypedArray
liegt.
Beispiele
Verwendung von load
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);
Atomics.add(ta, 0, 12);
Atomics.load(ta, 0); // 12
Spezifikationen
Specification |
---|
ECMAScript® 2025 Language Specification # sec-atomics.load |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
load |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support