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

The 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 code to show the working of this properties:

Code #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<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
    document.write(A.byteLength +"<br>");
    document.write(B.byteLength +"<br>");
    document.write(C.byteLength +"<br>");
    document.write(D.byteLength +"<br>");
    document.write(E.byteLength);
      
</script>

chevron_right


Output:

8
12
20
22
4


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.