slice
slice 方法 特性: arr.clice(start,end)
-
The original array will not be modified. 不改变原来的数组
-
index end is not included. 不包含end下标指向的元素
-
start :
Zero-based index at which to start extraction.
A negative index can be used, indicating an offset from the end of the sequence.
slice(-2)
extracts the last two elements in the sequence.If
start
is undefined,slice
starts from the index0
. -
end
OptionalZero-based index before which to end extraction.
slice
extracts up to but not includingend
. For example,slice(1,4)
extracts the second element through the fourth element (elements indexed 1, 2, and 3).A negative index can be used, indicating an offset from the end of the sequence.
slice(2,-1)
extracts the third element through the second-to-last element in the sequence.If
end
is omitted,slice
extracts through the end of the sequence (arr.length
).If
end
is greater than the length of the sequence,slice
extracts through to the end of the sequence (arr.length
).
应用 将伪数组转为数组
function list() {
return Array.prototype.slice.call(arguments);
}
console.log(list(1,2,3,4,5,5)); // [1,2,3,4,5,5];