title: jQuery.map() and iteration
body: <p>I'm working my way through the O'Reilly <em>jQuery Cookbook</em>. On p.65 there is an example that looks wrong to me, but I'm new to jQuery (less than a week) so I figure it is very likely that I am the one who is confused.</p>
  
  <p>The code intends to get the first three items from an ordered list &amp; do something with them; for simplicity's sake (on the book's part) in the selector, there is only one list on the page.</p>
  
  <p>They give the following code (I've simplified slightly, but not in the relevant portion); the outer two layers are, of course, boilerplate (a closure so that <code>$</code> will work as desired, and code to make this fire when the page loads).</p>
  
  <pre><code>(function($){
      $(document).ready(function(){
          var arr = $.map($('li'), function(item, index){
              while (index &lt; 3)
              {
                   return $(item).html();
              }
              return null;
          });
          /* do something with the resulting array; 
             I've deliberately simplified from the book here */
          alert(arr.join(",");
      });
  })(jQuery);
  </code></pre>
  
  <p>The explicit iteration (<code>while</code>) doesn't make sense to me. As I understand it, the inner anonymous function should be called once for each element of the array, so I would expect an <code>if</code>, not a <code>while</code>.</p>