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
- start
{Number}
:the index to start copying from
- 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.
var list = new 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 List(['Alice', 'Bob', 'Eve']);
var copy = list.slice();
copy.attr(); // ['Alice', 'Bob', 'Eve']
list === copy; // false