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

      function

      Insert and remove elements from a DefineList.

      • source

      list.splice(index[, howMany[, ...newItems]])

      Removes howMany items at index and adds newItems in their place.

      Parameters

      1. index {Number}:

        Where to start removing or inserting elements.

      2. howMany {Number}:

        The number of elements to remove If howMany is not provided, splice will remove all elements from index to the end of the DefineList.

      3. newItems {*}:

        Items to insert into the DefineList

      Returns

      {Array}:

      The elements removed by splice.

      Use

      splice lets you remove elements from and insert elements into a DefineList.

      This example demonstrates how to do surgery on a list of numbers:

      var list = new DefineList([0, 1, 2, 3]);
      
      // starting at index 2, remove one element and insert 'Alice' and 'Bob':
      list.splice(2, 1, 'Alice', 'Bob');
      list.get(); // [0, 1, 'Alice', 'Bob', 3]
      

      Events

      splice causes the DefineList it's called on to emit add events, remove events, and length events. If there are any elements to remove, a remove event, and a length event will be fired. If there are any elements to insert, a separate add event, and a separate length event will be fired.

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