Saturday, September 21, 2024
Google search engine
HomeLanguagesJavascriptJavaScript ArrayBuffer resizable Property

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.

Javascript




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.

Javascript




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:

  • 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

Recent Comments