JavaScript typedArray.buffer() and typedArray.byteLength() with Example
The Javascript typedArray.buffer() is a property in JavaScript which represents the ArrayBuffer referenced by a typedArray and the property typedArray.byteLength() represents the length of the typedArray in bytes.
Syntax:
typedArray.buffer
typedarray.byteLength
Parameters: It does not accept any parameter because it is a property, not a function.
Return values: It doesn’t return any value.
JavaScript examples to show the working of this property:
Example 1: In this example we will see the basic use of the JavaScript typedArray.buffer() and typedArray.byteLength() property in Javascript.
javascript
<script>
const buffer1 = new ArrayBuffer(8);
const buffer2 = new ArrayBuffer(12);
const buffer3 = new ArrayBuffer(20);
const buffer4 = new ArrayBuffer(22);
const buffer5 = new ArrayBuffer(4);
const A = new Uint16Array(buffer1);
const B = new Uint16Array(buffer2);
const C = new Uint16Array(buffer3);
const D = new Uint16Array(buffer4);
const E = new Uint16Array(buffer5);
console.log(A.byteLength);
console.log(B.byteLength);
console.log(C.byteLength);
console.log(D.byteLength);
console.log(E.byteLength);
</script>
|
Output:
8
12
20
22
4
Last Updated :
22 Dec, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...