mozilla

Revision 70208 of forEach

  • Revision slug: Talk:JavaScript/Reference/Global_Objects/Array/forEach
  • Revision title: forEach
  • Revision id: 70208
  • Created:
  • Creator: BenCollver
  • Is current revision? No
  • Comment

Revision Content

Is this a from _core_ of JavaScript 1.5? If so, is JS 1.5 Gecko only? Those extra features like forEach are Gecko only, and it should be mentioned that they should *_not_* be used on web pages. --Gandalf 07:18, 31 May 2005 (PDT)

Is there a way to make forEach make use of break?

{{ mediawiki.external("1") }}.forEach(function(value, index, array){

 print(value);
 //break?
 if (value>1){
   return false;//we could have some way to break when we return false
 }

}); //woulld print 1 2

--Porfirio 11:17, 22-06-2008

Another option would be to throw StopIteration and catch it within forEach().

--BenCollver 11:18, 13-08-2008

Revision Source

<p>Is this a from _core_ of JavaScript 1.5? If so, is JS 1.5 Gecko only?
Those extra features like forEach are Gecko only, and it should be mentioned that they should *_not_* be used on web pages.
--<a href="User:Gandalf">Gandalf</a> 07:18, 31 May 2005 (PDT)
</p><p>Is there a way to make forEach make use of break?
</p><p>{{ mediawiki.external("1") }}.forEach(function(value, index, array){
</p>
<pre class="eval"> print(value);
 //break?
 if (value&gt;1){
   return false;//we could have some way to break when we return false
 }
</pre>
<p>});
//woulld print 1 2
</p><p>--<a href="User:Porfirio">Porfirio</a> 11:17, 22-06-2008
</p><p>Another option would be to throw StopIteration and catch it within forEach().
</p><p>--<a href="User:BenCollver">BenCollver</a> 11:18, 13-08-2008
</p>
Revert to this revision