W3cubDocs

/JavaScript

sharedArrayBuffer.slice

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The SharedArrayBuffer.prototype.slice() method returns a new SharedArrayBuffer whose contents are a copy of this SharedArrayBuffer's bytes from begin, inclusive, up to end, exclusive. If either begin or end is negative, it refers to an index from the end of the array, as opposed to from the beginning. This method has the same algorithm as Array.prototype.slice().

Syntax

sab.slice()
sab.slice(begin)
sab.slice(begin, end)

Parameters

begin Optional

Zero-based index at which to begin extraction.

As a negative index, begin indicates an offset from the end of the sequence. slice(-2) extracts the last two elements in the sequence.

If begin is omitted, slice begins from index 0.

end Optional

Zero-based index at which to end extraction. slice extracts up to but not including end.

slice(1,4) extracts the second element up to the fourth element (elements indexed 1, 2, and 3).

As a negative index, end indicates 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 to the end of the sequence (sab.byteLength).

Return value

A new SharedArrayBuffer containing the extracted elements.

Examples

var sab = new SharedArrayBuffer(1024);
sab.slice();    // SharedArrayBuffer { byteLength: 1024 }
sab.slice(2);   // SharedArrayBuffer { byteLength: 1022 }
sab.slice(-2);  // SharedArrayBuffer { byteLength: 2 }
sab.slice(0, 1); // SharedArrayBuffer { byteLength: 1 }

Specifications

Specification Status Comment
ECMAScript Shared Memory and Atomics
The definition of 'SharedArrayBuffer.prototype.slice' in that specification.
Draft Initial definition.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support No support No support 52 (52) No support No support No support
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support No support No support 52.0 (52) No support No support No support

See also

© 2005–2017 Mozilla Developer Network and individual 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/SharedArrayBuffer/slice