forEach

Ok, in the end I didn't remove the old code as it isn't hosted anywhere (I thought the github reference contained the code) but inserted a faster implementation above while retaining the rest of the document.

Feel free to alter the text as English is not my mother tongue and I'm more concerned with the code quality that the English grammar ;-S

dotnetCarpenter 30 June 2012

<hr>

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

<hr>

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

jswisher 01 October 2011

<hr>

There is some mistype in Array.prototype.forEach:

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

<hr>

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

<hr>

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?

[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