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
相關用法
- JavaScript typedArray.lastIndexOf()用法及代碼示例
- JavaScript typedArray.keys()用法及代碼示例
- JavaScript typedArray.forEach()用法及代碼示例
- JavaScript typedArray.sort()用法及代碼示例
- JavaScript typedArray.slice()用法及代碼示例
- JavaScript typedArray.join()用法及代碼示例
- JavaScript typedArray.fill()用法及代碼示例
- JavaScript typedArray.some()用法及代碼示例
- JavaScript typedArray.reduceRight()用法及代碼示例
- JavaScript typedArray.indexOf()用法及代碼示例
- JavaScript typedArray.reduce()用法及代碼示例
- JavaScript typedArray.of()用法及代碼示例
- JavaScript typedArray.includes()用法及代碼示例
- JavaScript typedArray.set()用法及代碼示例
- JavaScript typedArray.reverse()用法及代碼示例
- JavaScript typedArray.map()用法及代碼示例
- JavaScript typedArray.name屬性用法及代碼示例
- JavaScript trimLeft()用法及代碼示例
- JavaScript trimStart()用法及代碼示例
- JavaScript toUpperCase()用法及代碼示例
- JavaScript toLowerCase()用法及代碼示例
- JavaScript Math cosh()用法及代碼示例
- JavaScript Math sinh()用法及代碼示例
- JavaScript Math sin()用法及代碼示例
- JavaScript Math cos()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 JavaScript typedArray.length() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。