set Method (Uint8ClampedArray)


Sets a value or an array of values.

uint8ClampedArray.set(index, value);
uint8ClampedArray.set(array, offset);


The index of the location to set.


The value to set.


A typed or untyped array of values to set.


The index in the current array at which the values are to be written.

If the input array is a typed array, the two arrays may use the same underlying ArrayBuffer. In this situation, setting the values takes place as if all the data had first been copied into a temporary buffer that does not overlap either of the arrays, and then the data from the temporary buffer is copied into the current array.

If the offset plus the length of the given array is out of range for the current typed array, an exception is raised.


The following example shows how to set the first element of the array.

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

    req.onreadystatechange = function () {
        if (req.readyState === 4) {
            var buffer = req.response;
            var dataView = new DataView(buffer);
            var intArr = new Uint8ClampedArray(buffer.byteLength);
            intArr.set(0, 9);


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.