forEach

  • Revision slug: Talk:JavaScript/Reference/Global_Objects/Array/forEach
  • Revision title: forEach
  • Revision id: 237529
  • Created:
  • Creator: dotnetCarpenter
  • Is current revision? No
  • Comment 68 words added

Revision Content

The Compatibility section goes to extraordinary lengths in providing a forEach implementation. A much more sane approach would be to count on the implementation to throw errors if wrong arguments are provided and implement this in fewer lines of code.

I've removed the lengthy example, while still linking to it and provided a much simpler and leaner implementation.

dotnetCarpenter 30 June 2012


I have released the write access restriction, but I will be watching changes closely.

jswisher 01 October 2011


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>The Compatibility section goes to extraordinary lengths in providing a forEach implementation. A much more sane approach would be to count on the implementation to throw errors if wrong arguments are provided and implement this in fewer lines of code.</p>
<p>I've removed the lengthy example, while still linking to it and provided a much simpler and leaner implementation.</p>
<p><a href="/User:dotnetCarpenter" rel="custom">dotnetCarpenter</a> 30 June 2012</p>
<hr>
<p>I have released the write access restriction, but I will be watching changes closely.</p>
<p><a href="/User:jswisher" rel="custom">jswisher</a> 01 October 2011</p>
<hr>
<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