Open In App

JavaScript ArrayBuffer resizable Property

JavaScript resizable property in ArrayBuffer is used to check whether an ArrayBuffer can be resized or not. It returns a boolean value. It is a read-only property whose value is set when maxByteLength is defined.

Syntax:



arr.resizable

Parameters: It does not accept any parameter.

Example 1: In this example, we will check if the ArrayBuffers are resizable.






let arr1 = new ArrayBuffer(8);
let arr2 = new ArrayBuffer(8, { maxByteLength: 24 });
 
console.log(arr1.resizable);
console.log(arr2.resizable);

Output:

false
true

Example 2: This example resizes the ArrayBuffer only if it is resizable.




function changeSize(arr, size) {
    if (arr.resizable) {
        arr.resize(size);
        return "Resized";
    }
    return "Maximum capacity reached";
}
 
let arr1 = new ArrayBuffer(8);
let arr2 = new ArrayBuffer(8, { maxByteLength: 24 });
 
console.log(changeSize(arr1, 24))
console.log(changeSize(arr2, 24))
 
console.log(arr1.byteLength);
console.log(arr2.byteLength);

Output:

Maximum capacity reached
Resized
8
24

Supported Browsers:

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

Article Tags :