This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.
The slice() method of TypedArray instances returns a copy of a portion of a typed array into a new typed array object selected from start to end (end not included) where start and end represent the index of items in that typed array. The original typed array will not be modified. This method has the same algorithm as Array.prototype.slice().
const bytes = new Uint8Array([10, 20, 30, 40, 50]); const byteSlice = bytes.slice(1, 3); console.log(byteSlice); // Expected output: Uint8Array [20, 30]
slice() slice(start) slice(start, end)
start OptionalZero-based index at which to start extraction, converted to an integer.
end OptionalZero-based index at which to end extraction, converted to an integer. slice() extracts up to but not including end.
A new typed array containing the extracted elements.
See Array.prototype.slice() for more details. This method is not generic and can only be called on typed array instances.
const bytes = new Uint8Array([1, 2, 3]); bytes.slice(1); // Uint8Array [ 2, 3 ] bytes.slice(2); // Uint8Array [ 3 ] bytes.slice(-2); // Uint8Array [ 2, 3 ] bytes.slice(0, 1); // Uint8Array [ 1 ]
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
slice |
45 | 12 | 38 | 32 | 10 | 45 | 38 | 32 | 10 | 5.0 | 45 | 10 | 1.0.0 | 1.0 | 4.0.0 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice