• function

Make a copy of a part of a List.

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

slice creates a copy of a portion of the List.


  1. start=0 {Number}Optional

    the index to start copying from

  2. end {Number}Optional

    the first index not to include in the copy If end is not supplied, slice will copy until the end of the 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