typedArray.values()是JavaScript中的內置函數,用於獲取typedArray()內容的指定值。
用法:
typedArray.values()
參數它不接受任何參數。
返回值:它返回給定typedArray對象的指定值。
代碼1:
<script>
// Constructing a new typedArray Uint8Array() with some value.
const A = new Uint8Array([ 5, 10, 15, 20, 25, 30 ]);
// Calling typedArray.values() function.
const B = A.values();
// Shifting array iterator to next element
// iterator assigned to 10
B.next();
// iterator assigned to 15
B.next();
// iterator assigned to 20
B.next();
// Printing value 20
document.write(B.next().value);
</script>
輸出:
20
代碼2:
<script>
// Constructing a new typedArray Uint8Array() with some value.
const A = new Uint8Array([5, 10, 15, 20, 25, 30]);
// Calling typedArray.values() function.
const B = A.values();
// Shifting array iterator to next element
// iterator assigned to 10
B.next();
// iterator assigned to 15
B.next();
// iterator assigned to 20
B.next();
// iterator assigned to 25
B.next();
// iterator assigned to 30
B.next();
// Now iterator go beyond the index
B.next();
document.write(B.next().value);
</script>
輸出:
undefined
這裏的輸出是不確定的,因為數組迭代器越過了上限。
相關用法
- Javascript typedArray.from()用法及代碼示例
- Javascript typedArray.of()用法及代碼示例
- Javascript weakSet.has()用法及代碼示例
- Javascript typedArray.map()用法及代碼示例
- Javascript weakSet.add()用法及代碼示例
- Javascript weakMap.set()用法及代碼示例
- Javascript weakMap.has()用法及代碼示例
- Javascript typedArray.every()用法及代碼示例
- Javascript getPrototypeOf()用法及代碼示例
- Javascript uneval()用法及代碼示例
- Javascript parseInt()用法及代碼示例
- Javascript parseFloat()用法及代碼示例
注:本文由純淨天空篩選整理自ShivamKD大神的英文原創作品 JavaScript | typedArray.values() with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。