Skip to content
Related Articles

Related Articles

Improve Article

JavaScript | typedArray.buffer() and typedArray.byteLength() with Example

  • Last Updated : 14 Feb, 2019
Geek Week

The typedArray.buffer() is a property in JavaScript which represents the ArrayBuffer referenced by a typedArray and the property typedArray.byteLength() represents the length of the typedArray in bytes.


Parameters: It does not accept any parameter because it is a property not a function.
Return values: It doesn’t return any value.

JavaScript code to show the working of this properties:

Code #1:

    // creating some ArrayBuffers with a size in bytes
    const buffer1 = new ArrayBuffer(8);
    const buffer2 = new ArrayBuffer(12);
    const buffer3 = new ArrayBuffer(20);
    const buffer4 = new ArrayBuffer(22);
    const buffer5 = new ArrayBuffer(4);
    // Creating typedArray object for above buffers
    const A = new Uint16Array(buffer1);
    const B = new Uint16Array(buffer2);
    const C = new Uint16Array(buffer3);
    const D = new Uint16Array(buffer4);
    const E = new Uint16Array(buffer5);
    // Getting the length of the arrayBuffer
    document.write(A.byteLength +"<br>");
    document.write(B.byteLength +"<br>");
    document.write(C.byteLength +"<br>");
    document.write(D.byteLength +"<br>");



Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!

My Personal Notes arrow_drop_up
Recommended Articles
Page :