Open In App

JavaScript typedArray.byteOffset Property

Last Updated : 15 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The typedArray.byteOffset is an inbuilt property in JavaScript that 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 returns the offset in bytes of a given typedArray from the start of its ArrayBuffer. 

Example:

javascript




// 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
console.log(a);
console.log(b);
console.log(c);
console.log(d);


Output:

0
4
5
8

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads