The
Iterator
function is a SpiderMonkey-specific feature, and will be removed at some point. For future-facing usages, consider using for..of loops and the iterator protocolSummary
The Iterator
function returns an object which implements legacy iterator protocol which iteratates over enumerable propeties of an Object.
Syntax
Iterator(object)
Parameters
-
object
- Object to iterator over propeties.
Description
An overview of the usage is available on the Iterators and Generators page.
Properties
Methods
-
Iterator.prototype.next
-
Returns next item in
[property_name, property_value]
format. it throws StopIteration if there is no more items.
Examples
Iterate over properties of an object.
var a = { x: 10, y: 20, }; var iter = Iterator(a); console.log(iter.next()); // ["x", 10] console.log(iter.next()); // ["y", 20] console.log(iter.next()); // throws StopIteration
Iterate over properties of an object with legacy destructuring for-in
statement.
var a = { x: 10, y: 20, }; for (var [name, value] in Iterator(a)) { console.log(name, value); // x 10 // y 20 }