DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
    • can-component
    • can-compute
    • can-connect
    • can-define
    • can-define/list/list
      • events
        • add
        • length
        • propertyName
        • remove
      • prototype
        • concat
        • filter
        • forEach
        • get
        • indexOf
        • join
        • map
        • on
        • pop
        • push
        • replace
        • reverse
        • serialize
        • set
        • shift
        • slice
        • sort
        • splice
        • unshift
        • *
        • #
      • static
        • extend
    • can-define/map/map
    • can-route
    • can-route-pushstate
    • can-set
    • can-stache
    • can-stache/helpers/route
    • can-stache-bindings
  • Ecosystem
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Core
  • /
  • can-define/list/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 DefineList.

      var names = new DefineList(['Alice']);
      names.push('Bob', 'Eve');
      names //-> DefineList['Alice','Bob', 'Eve']
      

      Parameters

      1. elements {*}:

        the elements to add to the DefineList

      Returns

      {Number}:

      the new length of the DefineList

      Use

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

      var list = new DefineList(['Alice']);
      
      list.push('Bob', 'Eve');
      list.get(); // ['Alice', 'Bob', 'Eve']
      

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

      var names = ['Bob', 'Eve'],
          list = new DefineList(['Alice']);
      
      list.push.apply(list, names);
      list.get(); // ['Alice', 'Bob', 'Eve']
      

      Events

      push causes 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.