{{jsSidebar("Objects")}}
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 is used to tell the end of the iteration in the legacy iterator protocol.
Syntax
StopIteration
Description
An overview of the usage is available on the Iterators and Generators page.
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
{{WhyNoSpecStart}}Non-standard. Not part of any current standards document.{{WhyNoSpecEnd}}
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatVersionUnknown}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatVersionUnknown}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |