DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
  • Infrastructure
  • Legacy
    • can-ejs
    • can-list
    • can-map
      • prototype
        • DEFAULT-ATTR
        • attr
        • bind
        • compute
        • each
        • removeAttr
        • serialize
        • unbind
      • static
        • keys
    • 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-map
  • /
  • each
  • / On this page
    • each

      function

      Call a function on each property of a Map.

      • source

      map.each( callback(item, propName ) )

      each iterates through the Map, calling a function for each property value and key.

      Parameters

      1. callback {function(item, propName)}:

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

      Returns

      {can-map}:

      this Map, for chaining

      var names = [];
      new Map({a: 'Alice', b: 'Bob', e: 'Eve'}).each(function(value, key) {
          names.push(value);
      });
      
      names; // ['Alice', 'Bob', 'Eve']
      
      names = [];
      new Map({a: 'Alice', b: 'Bob', e: 'Eve'}).each(function(value, key) {
          names.push(value);
          if(key === 'b') {
              return false;
          }
      });
      
      names; // ['Alice', 'Bob']
      

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