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.

Die values() Methode von TypedArray Instanzen gibt ein neues Array-Iterator-Objekt zurück, das den Wert jedes Elements im getypten Array durchläuft. Diese Methode verwendet denselben Algorithmus wie Array.prototype.values().

Probieren Sie es aus

const uint8 = new Uint8Array([10, 20, 30, 40, 50]);
const array1 = uint8.values();

array1.next();
array1.next();

console.log(array1.next().value);
// Expected output: 30

Syntax

js
values()

Parameter

Keine.

Rückgabewert

Beschreibung

Siehe Array.prototype.values() für weitere Details. Diese Methode ist nicht generisch und kann nur bei Instanzen von getypten Arrays aufgerufen werden.

Beispiele

Iteration mit for...of Schleife

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

Spezifikationen

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

Browser-Kompatibilität

Siehe auch