Tutorialspoint.dev

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:

<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>

Output:

0
4
5
8


This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter