类型数组的BYTES_PER_ELEMENT属性表示其中每个元素的字节数。
其语法如下
Float32Array.BYTES_PER_ELEMENT;
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var sizeOfFloat64Array = Float32Array.BYTES_PER_ELEMENT; document.write("Size of the float 32 array: "+sizeOfFloat64Array); document.write("<br>"); var sizeOfInt16Array = Int16Array.BYTES_PER_ELEMENT; document.write("Size of the int 16 array: "+sizeOfInt16Array); </script> </body> </html>
输出结果
Size of the float 32 array: 4 Size of the int 16 array: 2