TypedArr (TC02)
1: const buffer = new ArrayBuffer(16); // 16 bytes
2: const int32View = new Int32Array(buffer); // View as 32-bit integers (4 elements, each 4 bytes, as buffer is 16 byte long)
3: const uint8View = new Uint8Array(buffer); // View as 8-bit integers (16 elements)
4:
5: int32View[0] = 12345; // Modifies the underlying ArrayBuffer
6: console.log(uint8View); // The Uint8Array reflects the change made through the Int32Array
Creating Typed Arrays:
• From an ArrayBuffer:
Uint8Array(16) [
57, 48, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0
]
TypedArr context:
ES6 context:
Binary context:
Comments (
)
)
Link to this page:
http://www.vb-net.com/JavascriptES6/TC02.htm
|
|