The Javascript Int16Array slice()
method returns a sub typed array.
This method works the same as Array.prototype.slice()
.
Int16Array.slice([begin[, end]])
Parameter | Optional | Meaning |
---|---|---|
begin | Optional | Zero-based index to begin extraction. A negative index means the offset from the end. slice(-2) extracts the last two elements in the sequence. Default to 0. |
end | Optional | Zero-based index before which to end extraction. slice extracts up to but not including end. |
For example, slice(1,4) extracts the second element through the fourth element (elements indexed 1, 2, and 3).
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 (Int16Array.length).
Return a portion of an existing typed array
const uint8 = new Int16Array([1,2,3]);
let a = uint8.slice(1);
console.log(a);
a = uint8.slice(2);
console.log(a);
a = uint8.slice(-2);
console.log(a);
a = uint8.slice(0,1);
console.log(a);