JavaScript typedArray.values()用法示例

typedArray.values()是JavaScript中的内置函数, 用于获取typedArray()的内容的指定值。
语法如下:

typedArray.values()

参数它不接受任何参数。
返回值:它返回给定typedArray对象的指定值。
JavaScript代码显示此功能的工作方式:
代码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.values()用法示例】这里的输出是不确定的, 因为数组迭代器越过了上限。

    推荐阅读