slice
Make a copy of a part of a DefineList.
list.slice([start[, end]])
slice creates a copy of a portion of the DefineList.
import {DefineList} from "can";
const list = new DefineList(["Alice", "Bob", "Charlie", "Daniel", "Eve"]);
const newList = list.slice(1, 4);
console.log(newList.get()); //-> ["Bob", "Charlie", "Daniel"]
Parameters
- start
{Number}:The index to start copying from. Defaults to
0. - end
{Number}:The first index not to include in the copy If end is not supplied,
slicewill copy until the end of the list.
Use
slice is the simplest way to copy a DefineList:
import {DefineList} from "can";
const list = new DefineList(["Alice", "Bob", "Eve"]);
const copy = list.slice();
console.log(copy.get()); //-> ["Alice", "Bob", "Eve"]
console.log(list === copy); //-> false