• function

slice can.Observe.List.prototype.slice

 

Make a copy of a part of a List.

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

slice creates a copy of a portion of the List.

Parameters

  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.

Returns

{can.Observe.List}

a new can.Observe.List with the extracted elements

var list = new can.Observe.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.Observe.List(['Alice', 'Bob', 'Eve']);
var copy = list.slice();

copy.attr();   // ['Alice', 'Bob', 'Eve']
list === copy; // false