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

      function

      Make a copy of a part of a List.

      • source

      list.slice([start[, end]])

      slice creates a copy of a portion of the List.

      Parameters

      1. start {Number}:

        the index to start copying from

      2. end {Number}:

        the first index not to include in the copy If end is not supplied, slice will copy until the end of the list.

      Returns

      {can.List}:

      a new can.List with the extracted elements

      var list = new can.List(['Alice', 'Bob', 'Charlie', 'Daniel', 'Eve']);
      var newList = list.slice(1, 4);
      newList.attr(); // ['Bob', 'Charlie', 'Daniel']
      

      slice is the simplest way to copy a List:

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

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