DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
  • Infrastructure
  • Legacy
    • can-ejs
    • can-list
      • Prototype
        • attr
        • each
        • filter
        • map
        • reverse
        • splice
      • Static
        • Map
        • extend
    • can-map
    • can-map-backup
    • can-map-define
    • can-view-href
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Legacy
  • /
  • can-list
  • /
  • each
  • / On this page
    • each

      function

      Call a function on each element of a List.

      • source

      list.each( callback(item, index) )

      each iterates through the List, calling a function for each element.

      var list = new List([1, 2, 3]);
      
      list.each(function(elem){
          console.log(elem);
      });
      

      Parameters

      1. callback {function(*, Number)}:

        the function to call for each element The value and index of each element will be passed as the first and second arguments, respectively, to the callback. If the callback returns false, the loop will stop.

      Returns

      {can.List}:

      this List, for chaining

      var i = 0;
      new List([1, 10, 100]).each(function(element, index) {
          i += element;
      });
      
      i; // 111
      
      i = 0;
      new List([1, 10, 100]).each(function(element, index) {
          i += element;
          if(index >= 1) {
              return false;
          }
      });
      
      i; // 11
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.