JavaScript | typedArray.BYTES_PER_ELEMENT with Examples

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.

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<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>

chevron_right


Output:

1
1
1
2
2
4
4
4
8


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.