A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript-arraybuffer-resize-method/ below:

JavaScript ArrayBuffer resize() Method - GeeksforGeeks

JavaScript ArrayBuffer resize() Method

Last Updated : 18 May, 2023

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.

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:

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



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4