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, BigInt64Array, BigUint64Array 중 하나.

index

value를 저장할 typedArray의 인덱스.

value

저장할 숫자.

반환 값

저장된 값.

예외

  • typedArray가 허용된 정수형이 아닐 경우 TypeError가 발생합니다.
  • indextypedArray의 범위를 벗어날 경우 RangeError가 발생합니다.

예제

store() 사용하기

js
const sab = new SharedArrayBuffer(1024);
const 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 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

같이 보기