TypedArray.prototype.values()

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 实例的 values() 方法返回一个新的 数组迭代器 对象,该对象迭代类型化数组中每个项目的值。该方法与 Array.prototype.values() 的算法相同。

¥The values() method of TypedArray instances returns a new array iterator object that iterates the value of each item in the typed array. This method has the same algorithm as Array.prototype.values().

Try it

语法

¥Syntax

js
values()

参数

¥Parameters

没有任何。

¥None.

返回值

¥Return value

新的 可迭代的迭代器对象

¥A new iterable iterator object.

描述

¥Description

详细信息请参见 Array.prototype.values()。此方法不是通用的,只能在类型化数组实例上调用。

¥See Array.prototype.values() for more details. This method is not generic and can only be called on typed array instances.

示例

¥Examples

使用 for...of 循环进行迭代

¥Iteration using for...of loop

js
const arr = new Uint8Array([10, 20, 30, 40, 50]);
const values = arr.values();
for (const n of values) {
  console.log(n);
}

替代迭代

¥Alternative iteration

js
const arr = new Uint8Array([10, 20, 30, 40, 50]);
const values = arr.values();
console.log(values.next().value); // 10
console.log(values.next().value); // 20
console.log(values.next().value); // 30
console.log(values.next().value); // 40
console.log(values.next().value); // 50

规范

Specification
ECMAScript Language Specification
# sec-%typedarray%.prototype.values

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看