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

      function

      Add items to the beginning of a DefineList.

      • source

      list.unshift(...items)

      unshift adds items onto the beginning of a DefineList.

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

      Parameters

      1. items {*}:

        The items to add to the DefineList.

      Returns

      {Number}:

      The new length of the DefineList.

      Use

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

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

      Events

      unshift causes add and length events to be fired.

      See also

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

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