MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/d6d7ff2e2f9c

Non-standard. The StopIteration object is a SpiderMonkey-specific feature. For future-facing usages, consider using for..of loops and the iterator protocol.

The StopIteration object was used to tell the end of the iteration in the legacy iterator protocol. Do not use this ancient feature.

Syntax

StopIteration

Description

StopIteration is a part of legacy iterator protocol, and it will be removed at the same time as legacy iterator and legacy generator.

Examples

StopIteration is thrown by Iterator.

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

Throwing StopIteration.

function f() {
  yield 1;
  yield 2;
  throw StopIteration;
  yield 3; // this is not executed.
}

for (var n in f()) {
  console.log(n);   // 1
                    // 2
}

Specifications

Non-standard. Not part of any current standards document

See also

Document Tags and Contributors

 Contributors to this page: fscholz, nmve, arai
 Last updated by: fscholz,