Open In App

JavaScript typedArray.buffer() and typedArray.byteLength() with Example

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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>
    // creating some ArrayBuffers with a size in bytes
    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);
      
    // Creating typedArray object for above buffers
    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);
      
    // Getting the length of the arrayBuffer
    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
Previous
Next
Share your thoughts in the comments
Similar Reads