typedArray[Symbol.iterator]() returns an iterator over the elements of the typed array. You rarely call it by hand: for...of, the spread syntax [...ta], Array.from(ta), and destructuring such as const [a, b] = ta all call it for you. It is the same function as values(). Call it yourself to read elements one at a time with next().
Remember
ta[Symbol.iterator]() → iterator of elements
ta[Symbol.iterator] === ta.values // true
for (const v of ta) { } // calls ta[Symbol.iterator]()
[...ta] // calls it too
const [a, b] = ta; // and so does destructuring
Syntax
Use square brackets, because the key is the symbol Symbol.iterator, not a normal name.
JavaScript
typedArray[Symbol.iterator]()
Call
What it does
ta[Symbol.iterator]()
Get an iterator over the elements, exactly like ta.values().
ta[Symbol.iterator]().next()
Read the first element as { value, done }.
typeof x[Symbol.iterator]
"function" when x can be used in for...of.
Built into JavaScript since ES2015 on all 11 typed array types. This method is what makes a typed array iterable.
Library declarations
JavaScript
TypedArray.prototype[Symbol.iterator]() // returns an Array Iterator
// TypedArray.prototype[Symbol.iterator] === TypedArray.prototype.values
// iterator.next() -> { value: element, done: false }
// after the last element -> { value: undefined, done: true }
Parameters
Parameter
Description
(none)
[Symbol.iterator]() has no parameters. Extra arguments are ignored.
Return Value
Return Value
Description
Array Iterator
A new iterator object over the elements, the same as values() returns. Values are numbers, or BigInts on the two BigInt types.
JavaScript Examples
Example 1 — Read a Small Packet Step by Step
A tiny message format: the first byte says how many letters follow. Calling [Symbol.iterator]() ourselves lets us pull exactly that many bytes.
JavaScript
const packet = new Uint8Array([3, 65, 66, 67]);
const reader = packet[Symbol.iterator]();
const count = reader.next().value;
let text = '';
for (let n = 0; n < count; n++) {
text += String.fromCharCode(reader.next().value);
}
console.log('length byte: ' + count);
console.log('text: ' + text);
console.log(reader.next().done);
The first next() reads the header.reader.next().value takes byte 0, the number 3, which says three letters follow.
The same iterator continues. Each further next() picks up where the last one stopped, so the loop reads bytes 65, 66, and 67 and turns them into A, B, and C.
Nothing is left over. All four bytes were consumed, so one more next() reports done as true.
Example 2 — It Is What for...of Calls
We walk an Int32Array twice: once by calling [Symbol.iterator]() ourselves and once with a normal for...of loop.
JavaScript
const grid = new Int32Array([7, -7, 70]);
console.log(grid[Symbol.iterator] === grid.values); // true
const bySymbol = [];
const it = grid[Symbol.iterator]();
for (let r = it.next(); !r.done; r = it.next()) bySymbol.push(r.value);
const byLoop = [];
for (const v of grid) byLoop.push(v);
console.log(bySymbol.join(' '));
console.log(byLoop.join(' '));
One function, two names. The strict equality check proves that grid[Symbol.iterator] and grid.values are the very same function object.
The manual loop. The classic for loop calls next() until r.done is true and pushes every r.value into bySymbol.
for...of does the same work.for (const v of grid) calls [Symbol.iterator]() behind the scenes, so both lists print the identical text 7 -7 70.
Example 3 — Make Your Own Object Iterable
A playlist stores song IDs in a Uint16Array. Its own [Symbol.iterator]() hands back the typed array's iterator, so spread and destructuring work on it.
A method with a symbol name. The object defines [Symbol.iterator]() and simply returns the iterator of its ids typed array.
Spread and destructuring now work.[...playlist] lists all three IDs, and const [first, second] = playlist takes the first two, which add up to 1003.
Every typed array is iterable. Checking typeof on a Float32Array shows function: all 11 types inherit this iterator method.
Compatibility
Browser & Runtime Support
TypedArray.prototype[Symbol.iterator]() is part of ES2015 (ES6), the same edition that introduced symbols, iterators, and for...of.
✓ Baseline · ES2015
TypedArray.prototype[Symbol.iterator]()
Supported in every modern browser, plus Node.js, Deno, and Bun.
98%Modern browser support
Google ChromeAll modern versions
Full support
Mozilla FirefoxAll modern versions
Full support
Apple SafariAll modern versions
Full support
Microsoft EdgeAll modern versions
Full support
Node.jsAll current releases
Supported
DenoAll releases
Supported
Internet ExplorerIE 10 and 11 have typed arrays, but not this method
Not supported
[Symbol.iterator]()Excellent
Bottom line: Safe everywhere modern JavaScript runs. Internet Explorer has no Symbol at all, so neither this method nor for...of exists there.
Frequently Asked Questions
It is the built-in method that returns an iterator over the elements. JavaScript calls it automatically whenever you use a typed array in for...of, spread, Array.from(), or array destructuring.
Yes. ta[Symbol.iterator] === ta.values is true, so both return the same kind of iterator with the same elements in the same order.
Symbol.iterator is a symbol, not a normal property name, so ta.Symbol.iterator does not work. Square brackets accept any key, including a symbol.
for...of loops, the spread syntax [...ta], Array.from(ta), array destructuring such as const [a, b] = ta, and new Set(ta).
Yes. Every type inherits it from the hidden TypedArray parent class, since ES2015. On BigInt64Array and BigUint64Array the iterator gives BigInt values.