| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | dev_langs | ms.assetid | caps.latest.revision | author | ms.author | manager | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
slice Method (ArrayBuffer) | Microsoft Docs |
01/18/2017 |
windows-client-threshold |
|
language-reference |
|
2dcc51ff-f444-4d51-80ba-3bcd845ba0ae |
5 |
mikejo5000 |
mikejo |
ghogen |
slice Method (ArrayBuffer)
Returns a section of an ArrayBuffer.
Syntax
arrayBufferObj.slice(start, [end])
Parameters
arrayBufferObj
Required. The ArrayBuffer object the section will be copied from.
start
Required. The byte index of the beginning of the section to be copied.
end
Optional. The byte index of the end of the section to be copied.
Remarks
The slice method returns an ArrayBuffer object that contains the specified portion of arrayBufferObj.
The slice method copies up to, but not including, the byte indicated by end. If start or end is negative, the specified index is treated as length + start or end, respectively, where length is the length of the ArrayBuffer. If end is omitted, extraction continues to the end of arrayBufferObj. If end occurs before start, no bytes are copied to the new ArrayBuffer.
Example
The following examples show how to use the slice method.
var req = new XMLHttpRequest();
req.open('GET', "http://www.example.com");
req.responseType = "arraybuffer";
req.send();
req.onreadystatechange = function () {
if (req.readyState === 4) {
var buffer1 = req.response;
var buffer2 = buffer1.slice(40, 48);
var dataview = new DataView(buffer2);
var ints = new Int32Array(buffer2.byteLength / 4);
for (var i = 0; i < ints.length; i++) {
ints[i] = dataview.getInt32(i * 4);
}
alert(ints[1]);
}
} Requirements
[!INCLUDEjsv11_winonly]