Wednesday, July 3, 2024
HomeLanguagesJavascriptJavaScript ArrayBuffer Reference

JavaScript ArrayBuffer Reference

ArrayBuffer is used to represent a generic, fixed-length raw binary data buffer. The contents of an ArrayBuffer cannot be directly manipulated and can only be accessed through a DataView Object or one of the typed array objects. These Objects are used to read and write the contents of the buffer. 

Syntax:

new ArrayBuffer(byteLen)

Parameters: It takes one parameter.

  • byteLen: It is the byte length of the ArrayBuffer.

Return Type: It returns an ArrayBuffer object.

Example: This example creates an ArrayBuffer object

Javascript




const buffer = new ArrayBuffer(8);
const view = new Int32Array(buffer);
console.log(view);


Output

Int32Array(2) [ 0, 0 ]

The complete list of JavaScript ArrayBuffer is listed below:

JavaScript ArrayBuffer Constructor: In JavaScript, a constructor gets called when an object is created using the new keyword.

Constructor Description Example
ArrayBuffer() Returns the ArrayBuffer object

JavaScript ArrayBuffer Properties: A JavaScript property is a member of an object that associates a key with a value. 

  • Instance Property: An instance property is a property that has a new copy for every new instance of the class.
Instance Properties Description Example
constructor Returns the ArrayBuffer constructor function for the object
byteLength Specifies the byte length of the ArrayBuffer
maxByteLength Specified the max length to which the size of ArrayBuffer can be increased in bytes
resizable Returns a boolean which tells whether the array can be resized

JavaScript ArrayBuffer Methods:  JavaScript methods are the actions that can be performed on objects. There are two types of Number methods in JavaScript.

  • Static Methods: If the method is called using the ArrayBuffer class itself then it is called a static method.

Static Methods

Description

Example

isView()  It checks given an argument for the function is a typed array or not.
  • Instance Methods:  If the method is called on an instance of an ArrayBuffer then it is called an instance method.
Instance Methods Description Example
resize() Resizes the ArrayBuffer if possible
slice() Returns new ArrayBuffer with the sliced value

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments