JavaScript | typedArray.byteOffset property

The typedArray.byteOffset is an inbuilt property in JavaScript which is used to return the offset in bytes of a given typedArray from the start of its ArrayBuffer.
Syntax:

typedArray.byteOffset

Parameter: It does not accept any parameter because it is a property not a function.
Return value: It return the offset in bytes of a given typedArray from the start of its ArrayBuffer.
JavaScript code to show the working of this property:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
  
    // Constructing some ArrayBuffers
    var buffer1 = new ArrayBuffer(2);
    var buffer2 = new ArrayBuffer(8);
    var buffer3 = new ArrayBuffer(16);
    var buffer4 = new ArrayBuffer(32);
  
    // Constructing some typedArray with
    // parameter of above buffers
    var A = new Uint8Array(buffer1);
    var B = new Uint8Array(buffer2, 4);
    var C = new Uint8Array(buffer3, 5);
    var D = new Uint8Array(buffer4, 8);
  
   // Calling byteOffset property
    a = A.byteOffset;
    b = B.byteOffset;
    c = C.byteOffset;
    d = D.byteOffset;
  
   // Printing the offset in bytes of
   // the above typedArray from the start
   // of its ArrayBuffer
   document.write(a + "<br>");
   document.write(b + "<br>");
   document.write(c + "<br>");
   document.write(d);
  
</script>

chevron_right


Output:

0
4
5
8


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.