Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript | typedArray.BYTES_PER_ELEMENT with Examples

  • Last Updated : 03 Aug, 2018

The typedArray.BYTES_PER_ELEMENT is an inbuilt property in JavaScript which is used to return the size in bytes of the each element in an given typedArray.
Syntax:

typedArray.BYTES_PER_ELEMENT;

Parameter: It does not accept any parameter because it is a property not a function.

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!

Return value: It returns the size in bytes of the each element in an given tyepedArray.
JavaScript code to show the working of this function:




<script>
  
    // Calling BYTES_PER_ELEMENT on some typedArray
    a = Int8Array.BYTES_PER_ELEMENT;
    b = Uint8Array.BYTES_PER_ELEMENT;
    c = Uint8ClampedArray.BYTES_PER_ELEMENT;
    d = Int16Array.BYTES_PER_ELEMENT;
    e = Uint16Array.BYTES_PER_ELEMENT;
    f = Int32Array.BYTES_PER_ELEMENT;
    g = Uint32Array.BYTES_PER_ELEMENT;
    h = Float32Array.BYTES_PER_ELEMENT;
    i = Float64Array.BYTES_PER_ELEMENT;
  
   // Printing the size in bytes of the
   // each element in the given typedArray.
   document.write(a + "<br>");
   document.write(b + "<br>");
   document.write(c + "<br>");
   document.write(d + "<br>");
   document.write(e + "<br>");
   document.write(f + "<br>");
   document.write(g + "<br>");
   document.write(h + "<br>");
   document.write(i);
  
</script>

Output:

1
1
1
2
2
4
4
4
8
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!