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
  • /
  • push
  • / On this page
    • push

      function

      Add elements to the end of a list.

      • source

      list.push(...elements)

      push adds elements onto the end of a List.

      Parameters

      1. elements {*}:

        the elements to add to the List

      Returns

      {Number}:

      the new length of the List

      push adds elements onto the end of a List here is an example:

      var list = new can.List(['Alice']);
      
      list.push('Bob', 'Eve');
      list.attr(); // ['Alice', 'Bob', 'Eve']
      

      If you have an array you want to concatenate to the end of the List, you can use apply:

      var names = ['Bob', 'Eve'],
          list = new can.List(['Alice']);
      
      list.push.apply(list, names);
      list.attr(); // ['Alice', 'Bob', 'Eve']
      

      Events

      push causes change, add, and length events to be fired.

      See also

      push has a counterpart in pop, or you may be looking for unshift and its counterpart shift.

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