mozilla

Revision 70210 of forEach

  • Revision slug: Talk:JavaScript/Reference/Global_Objects/Array/forEach
  • Revision title: forEach
  • Revision id: 70210
  • Created:
  • Creator: pozadi
  • Is current revision? No
  • Comment 25 words added

Revision Content

There is some mistype in Array.prototype.forEach:

kValue = O[ Pk ]; should be kValue = O[ k ];

 


This page has been the target of a revert war, and so write access to it has been restricted. If you wish to make changes, and especially if you wish to revert another user's changes, please either add a comment here, or post to dev-mdc@lists.mozila.org, explaining the change you desire.

jswisher 15 Aug 2011

 


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>There is some mistype in <code>Array.prototype.forEach</code>:</p>
<p><code>kValue = O[ Pk ];</code> should be <code>kValue = O[ k ];</code></p>
<p> </p>
<hr>
<p>This page has been the target of a revert war, and so write access to it has been restricted. If you wish to make changes, and especially if you wish to revert another user's changes, please either add a comment here, or post to <a class=" link-mailto" href="mailto:dev-mdc@lists.mozila.org" rel="freelink">dev-mdc@lists.mozila.org</a>, explaining the change you desire.</p>
<p><a class="internal" href="/User:jswisher" title="User:jswisher">jswisher</a> 15 Aug 2011</p>
<p> </p>
<hr>
<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" title="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" title="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" title="User:BenCollver">BenCollver</a> 11:18, 13-08-2008</p>
Revert to this revision