Javascript Uint8ClampedArray slice()

Introduction

The Javascript Uint8ClampedArray slice() method returns a sub typed array.

This method works the same as Array.prototype.slice().

Uint8ClampedArray.slice([begin[, end]])
Parameter OptionalMeaning
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 (Uint8ClampedArray.length).

Return a portion of an existing typed array

const uint8 = new Uint8ClampedArray([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);



PreviousNext

Related