Looking at the examples for Uint8ClampedArray and Uint8Array, it looks like the difference is how values are treated when assigned.
If you are trying to set one element to a clamped array to any value outside of the range 0-255, it will simply default to 0 or 255 (depending on whether the value is smaller or larger). A normal Uint8Array array just takes the first 8 bit of the value.
Examples:
var x = new Uint8ClampedArray([17, -45.3]);
console.log(x[0]); // 17
console.log(x[1]); // 0
console.log(x.length); // 2
var x = new Uint8Array([17, -45.3]);
console.log(x[0]); // 17
console.log(x[1]); // 211
console.log(x.length); // 2
Answer from Felix Kling on Stack OverflowMDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Uint8ClampedArray
Uint8ClampedArray - JavaScript - MDN Web Docs
July 10, 2025 - Returns a number value of the element size. 1 in the case of Uint8ClampedArray.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Uint8ClampedArray › Uint8ClampedArray
Uint8ClampedArray() constructor - JavaScript - MDN Web Docs
July 10, 2025 - // From a length const uint8c = new Uint8ClampedArray(2); uint8c[0] = 42; uint8c[1] = 1337; console.log(uint8c[0]); // 42 console.log(uint8c[1]); // 255 (clamped) console.log(uint8c.length); // 2 console.log(uint8c.BYTES_PER_ELEMENT); // 1 // From an array const x = new Uint8ClampedArray([21, 31]); console.log(x[1]); // 31 // From another TypedArray const y = new Uint8ClampedArray(x); console.log(y[0]); // 21 // From an ArrayBuffer const buffer = new ArrayBuffer(8); const z = new Uint8ClampedArray(buffer, 1, 4); console.log(z.byteOffset); // 1 // From an iterable const iterable = (function* () { yield* [1, 2, 3]; })(); const uint8cFromIterable = new Uint8ClampedArray(iterable); console.log(uint8cFromIterable); // Uint8ClampedArray [1, 2, 3]
W3cubDocs
docs.w3cub.com › javascript › global_objects › uint8clampedarray
Uint8ClampedArray - JavaScript - W3cubDocs
August 7, 2022 - Returns a number value of the element size. 1 in the case of a Uint8ClampedArray.
Nodesource
v8docs.nodesource.com › node-0.12 › d9 › d36 › classv8_1_1_uint8_clamped_array.html
v8: Uint8ClampedArray Class Reference
An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
JavaScripture
javascripture.com › Uint8ClampedArray
Uint8ClampedArray JavaScript API
Uint8ClampedArray is similar to an Array where each item is a 8 bit (1 byte) unsigned integer. Values stored in this array are clamped to the range 0-255.
W3Schools
w3schools.com › Jsref › jsref_typed_uint8clampedarray.asp
JavaScript Uint8ClampedArray
Uint8ClampedArray contents are initialized to 0 by default. The difference between an Uint8Array and an Uint8ClampedArray is how values are added.
Rust
docs.rs › js-sys › latest › js_sys › struct.Uint8ClampedArray.html
Uint8ClampedArray in js_sys - Rust
An Uint8ClampedArray() which creates an array with the given buffer but is a view starting at byte_offset for length elements. ... The fill() method fills all the elements of an array from a start index to an end index with a static value.
Medium
medium.com › @j622amilah › javascript-basics-6-4b681b792298
JavaScript Basics 6. A list of conversion methods for… | by Practicing DatScy | Medium
November 22, 2024 - async function convert_canvas_to_base64str(ctx, canvasElement) { // ----------------------------- // Get canvas image const uint8ClampedArray = await ctx.getImageData(0, 0, canvasElement.width, canvasElement.height); // TypedArray Uint8ClampedArray // console.log('uint8ClampedArray: ', uint8ClampedArray); // Convert TypedArray to normalArray const normalArray = await Array.from(uint8ClampedArray.data); // console.log('normalArray: ', normalArray); // Convert [normalArray of bytes] to text_characters var ASCII_stringArray = normalArray.map((val) => { return String.fromCharCode(val); }); // cons
Reality Ripple
udn.realityripple.com › docs › Web › JavaScript › Reference › Global_Objects › Uint8ClampedArray
Uint8ClampedArray - JavaScript - UDN Web Docs: MDN Backup
The Uint8ClampedArray typed array represents an array of 8-bit unsigned integers clamped to 0-255; if you specified a value that is out of the range of [0,255], 0 or 255 will be set instead; if you specify a non-integer, the nearest integer will be set. The contents are initialized to 0.
W3Schools
w3schools.com › jsref › jsref_obj_typed_array.asp
JavaScript Typed Arrays
Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array BigInt64Array BigUint64Array Float16Array Float32Array Float64Array JS Typed Reference
GeeksforGeeks
geeksforgeeks.org › javascript-uint8clampedarray-of-method
JavaScript Uint8ClampedArray.of() Method | GeeksforGeeks
December 9, 2022 - It allows you to transform an existing array or iterable into a new Uint8Array instance, where each element of the new array is represented as an 8-bit unsigned integer.
MDN
mdn2.netlify.app › en-us › docs › web › javascript › reference › global_objects › uint8clampedarray › uint8clampedarray
Uint8ClampedArray() constructor - JavaScript | MDN
February 18, 2022 - ... When called with a typedArray ... copied into a new typed array. Each value in typedArray is converted to the corresponding type of the constructor before being copied into the new array....
Html5index
html5index.org › Typed Arrays - Uint8ClampedArray.html
Typed Arrays - Uint8ClampedArray
Uint8ClampedArray is defined in order to replace CanvasPixelArray.