当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


JavaScript typedArray.length()用法及代码示例


typedArray.length 是 JavaScript 中的内置属性,用于返回给定 typedArray 的长度。

用法:

typedArray.length

参数:它不接受任何参数,因为它是属性而不是函数。返回值:它返回给定 typedArray 的长度。

示例 1:

javascript


// Creating a typedArray with some elements 
var A = new Uint8Array([5, 10, 15, 15, 5, 20, 10]); 
var B = new Uint8Array([5, 10]); 
var C = new Uint8Array([5, 10, 15]); 
var D = new Uint8Array([5, 10, 15, 15, 5]); 
var E = new Uint8Array([5, 10, 15, 15, 5, 20]); 
  
// Calling length() function 
b = A.length      
c = B.length     
d = C.length   
e = D.length 
f = E.length 
  
  
// Printing the length of the typedArray 
console.log(b); 
console.log(c); 
console.log(d); 
console.log(e); 
console.log(f);

输出:

7
2
3
5
6

示例 2:

javascript


// Creating some ArrayBuffer with a size in bytes 
const A = new ArrayBuffer(8); 
const B = new ArrayBuffer(6); 
const C = new ArrayBuffer(16); 
const D = new ArrayBuffer(32); 
  
// Creating some typedArray with the above sizes  
// of the buffer 
const E = new Uint8Array(A); 
const F = new Uint8Array(B); 
const G = new Uint8Array(C); 
const H = new Uint8Array(D); 
  
// Calling length property 
a = E.length 
b = F.length 
c = G.length 
d = H.length 
  
// Printing the length of the typedArray 
console.log(a); 
console.log(b); 
console.log(c); 
console.log(d);

输出:

8
6
16
32


相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 JavaScript typedArray.length() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。