Copyright ©

Prototype Enumerable each() Method

previous next


This method is the cornerstone of Enumerable. It lets you iterate over all the elements in a generic fashion, then returns the Enumerable, thereby allowing chain-calling.

The optional context parameter is what the iterator function will be bound to. If used, the this keyword inside the iterator will point to the object given by the argument.



Return Value :


<title>Prototype examples</title>
<script type="text/javascript" 


function showResult(){
   ['one', 'two', 'three'].each(function(s) {
     alert("First loop : " + s);

   [ 'hello', 'world'].each(function(s, index) {
     alert("Second Loop : " +  index + ': ' + s);



  <p>Click the button to see the result.</p>
  <br />
  <br />
  <input type="button" value="Result" onclick="showResult();"/>


To understand it in better way you can Try it yourself.

previous next

Copyright ©