slice Method (ArrayBuffer)


Returns a section of an ArrayBuffer.

arrayBufferObj.slice(start, [end]) 


Required. The ArrayBuffer object the section will be copied from.


Required. The byte index of the beginning of the section to be copied.


Optional. The byte index of the end of the section to be copied.

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.


The following examples show how to use the slice method.

var req = new XMLHttpRequest();'GET', "");
    req.responseType = "arraybuffer";

    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);


Supported in the Internet Explorer 11 standards document mode. Also supported in Windows Store apps (Windows 8.1). See Version Information.

Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards. Not supported in Windows 8 or Windows Phone 8.1.