Wednesday, July 3, 2024
HomeLanguagesJavascriptJavaScript ArrayBuffer resize() Method

JavaScript ArrayBuffer resize() Method

JavaScript resize() method in ArrayBuffer is used to increase or decrease the size of ArrayBuffer in JavaScript. This method specifies the change in length in bytes and the specified length cannot be greater than the maxByteLength property of the array Buffer.

Syntax:

resize(len)

Parameter: This method takes only a single parameter.

  • len: This is the new length of the arrayBuffer in bytes.

Return Value: An undefined value.

Example 1: This method increases the size of ArrayBuffer which can be confirmed using the byteLength() method.

Javascript




let arr = new ArrayBuffer(12, { maxByteLength: 24 });
console.log(arr.byteLength);
 
arr.resize(18);
console.log(arr.byteLength);


Output: The increased size can never be greater than the maximum byte length the of the Array Buffer

12
18

Example 2: This example shrinks the size of ArrayBuffer. We will use the byteLength() method to decrease the size.

Javascript




let arr = new ArrayBuffer(24, { maxByteLength: 24 });
console.log(arr.byteLength);
 
arr.resize(18);
console.log(arr.byteLength);


Output:

24
18

Supported Browsers:

  • Chrome
  • Edge
  • Safari

We have a complete list of ArrayBuffer methods and properties, to check Please go through the JavaScript ArrayBuffer Reference article.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

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