Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

slice Method (ArrayBuffer)

Returns a section of an ArrayBuffer.

arrayBufferObj.slice(start, [end]) 

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.

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();
    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]);
        }
    }

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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft