Thursday, October 16, 2025
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!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11953 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS