Atomics.store() is an inbuilt method that is used to store a specific value at a specific position in an array. This method accepts an Integer typed array, index and the value as arguments.
Atomics.store(typedArray, index, value);
Whenever we want to store a value at a specific place and wants to return the stored value then Atomics.store() is used.
One should note that Atomics are used with SharedArrayBuffer(generic fixed-length binary data buffer) objects. They cant be used with a new operator or can't be invoked as a function.
In the following example initially SharedArrayBuffer object is created. Then an array 'arr' is taken and assigned a value '7' initially at index 1. later on using Atomics.store() the value 7 at index 1 is replaced with value 3 and the updated value is returned. For confirmation whether the new value is stored or not, Atomics.load() method, which will give the final updated array, is used and the updated value is displayed in the output.
<html> <body> <script> var buf = new SharedArrayBuffer(25); var arr = new Uint8Array(buf); arr = 7; var res = Atomics.store(arr, 1, 3) document.write(res); document.write("</br>"); document.write(Atomics.load(arr,1)); </script> </body> </html>