This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The slice() method of ArrayBuffer instances returns a new ArrayBuffer whose contents are a copy of this ArrayBuffer's bytes from start, inclusive, up to end, exclusive. If either start or end is negative, it refers to an index from the end of the array, as opposed to from the beginning.
// Create an ArrayBuffer with a size in bytes const buffer = new ArrayBuffer(16); const int32View = new Int32Array(buffer); // Produces Int32Array [0, 0, 0, 0] int32View[1] = 42; const sliced = new Int32Array(buffer.slice(4, 12)); // Produces Int32Array [42, 0] console.log(sliced[0]); // Expected output: 42
slice() slice(start) slice(start, end)
start OptionalZero-based index at which to start extraction, converted to an integer.
-buffer.length <= start < 0, start + buffer.length is used.start < -buffer.length or start is omitted, 0 is used.start >= buffer.length, an empty buffer is returned.end OptionalZero-based index at which to end extraction, converted to an integer. slice() extracts up to but not including end.
-buffer.length <= end < 0, end + buffer.length is used.end < -buffer.length, 0 is used.end >= buffer.length or end is omitted is undefined, buffer.length is used, causing all elements until the end to be extracted.end implies a position before or at the position that start implies, an empty buffer is returned.A new ArrayBuffer containing the extracted elements. It is not resizable, even if the original was.
const buf1 = new ArrayBuffer(8); const buf2 = buf1.slice(0);
| 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 |
17 | 12 | 12The non-standardArrayBuffer.slice() method has been removed in Firefox 53 (but the standardized version ArrayBuffer.prototype.slice() is kept. |
12.1 | 5.1 | 18 | 14The non-standardArrayBuffer.slice() method has been removed in Firefox for Android 53 (but the standardized version ArrayBuffer.prototype.slice() is kept. |
12.1 | 6 | 1.0 | 4.4 | 6 | 1.0.0 | 1.0 | 0.12.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/ArrayBuffer/slice