TypedArray.prototype.keys()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.
TypedArray
实例的 keys()
方法返回一个新的 数组迭代器 对象,其中包含类型化数组中每个索引的键。该方法与 Array.prototype.keys()
的算法相同。
¥The keys()
method of TypedArray
instances returns a new array iterator object that contains the keys for each index in the typed array. This method has the same algorithm as Array.prototype.keys()
.
Try it
语法
参数
返回值
描述
¥Description
详细信息请参见 Array.prototype.keys()
。此方法不是通用的,只能在类型化数组实例上调用。
¥See Array.prototype.keys()
for more details. This method is not generic and can only be called on typed array instances.
示例
使用 for...of 循环进行迭代
替代迭代
¥Alternative iteration
js
const arr = new Uint8Array([10, 20, 30, 40, 50]);
const arrKeys = arr.keys();
console.log(arrKeys.next().value); // 0
console.log(arrKeys.next().value); // 1
console.log(arrKeys.next().value); // 2
console.log(arrKeys.next().value); // 3
console.log(arrKeys.next().value); // 4
规范
Specification |
---|
ECMAScript Language Specification # sec-%typedarray%.prototype.keys |
浏览器兼容性
BCD tables only load in the browser