DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • prototype
    • concat
    • forEach
    • indexOf
    • join
    • pop
    • push
    • replace
    • reverse
    • shift
    • slice
    • splice
    • unshift
  • static
    • can.List.Map
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • can.List
  • /
  • forEach
  • / On this page
    • forEach

      function

      Call a function for each element of a List.

      • source

      list.forEach(callback[, thisArg])

      Parameters

      1. callback {function(element, index, list)}:

        a function to call with each element of the List The three parameters that callback gets passed are element, the element at index, index the current element of the list, and list the List the elements are coming from. callback is not invoked for List elements that were never initialized.

      2. thisArg {Object}:

        the object to use as this inside the callback

      forEach calls a callback for each element in the List.

      var list = new can.List([1, 2, 3]);
      list.forEach(function(element, index, list) {
          list.attr(index, element * element);
      });
      list.attr(); // [1, 4, 9]
      

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