JavaScript typedArray.BYTES_PER_ELEMENT用法实例

2021年5月6日17:05:04 发表评论 103 次浏览

typedArray.BYTES_PER_ELEMENT是JavaScript中的内置属性, 用于返回给定typedArray中每个元素的大小(以字节为单位)。

语法如下:

typedArray.BYTES_PER_ELEMENT;

参数:它不接受任何参数, 因为它是属性而不是函数。

返回值:

它返回给定tyepedArray中每个元素的大小(以字节为单位)。

JavaScript代码显示此功能的工作方式:

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

输出如下:

1
1
1
2
2
4
4
4
8

一盏木

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: