[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray [Back]  [Original]

Uint8ClampedArray - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Uint8ClampedArray

20157

Uint8ClampedArray8 0-255 8 [0,255] 0 255 0

new Uint8ClampedArray(length);
new Uint8ClampedArray(typedArray);
new Uint8ClampedArray(object);
new Uint8ClampedArray(buffer [, byteOffset [, length]]);

TypedArray

Uint8ClampedArray.BYTES_PER_ELEMENT

Uint8ClampedArray 1

Uint8ClampedArray.prototype.length

0 Uint8ClampedArray.prototype.length

Uint8ClampedArray.prototype

TypedArray

Uint8ClampedArray.from()

Uint8ClampedArray Array.from()

Uint8ClampedArray.of()

Uint8ClampedArray Array.of()

TypedArray

Uint8ClampedArray.prototype.constructor

Uint8ClampedArray

Uint8ClampedArray.prototype.buffer

Uint8ClampedArray ArrayBuffer

Uint8ClampedArray.prototype.byteLength

ArrayBuffer Uint8ClampedArray

Uint8ClampedArray.prototype.byteOffset

ArrayBuffer Uint8ClampedArray

Uint8ClampedArray.prototype.length

UintClamped8Array

TypedArray

Uint8ClampedArray

js
// From a length
var uintc8 = new Uint8ClampedArray(2);
uintc8[0] = 42;
uintc8[1] = 1337;
console.log(uintc8[0]); // 42
console.log(uintc8[1]); // 255 (clamped)
console.log(uintc8.length); // 2
console.log(uintc8.BYTES_PER_ELEMENT); // 1

// From an array
var arr = new Uint8ClampedArray([21, 31]);
console.log(arr[1]); // 31

// From another TypedArray
var x = new Uint8ClampedArray([21, 31]);
var y = new Uint8ClampedArray(x);
console.log(y[0]); // 21

// From an ArrayBuffer
var buffer = new ArrayBuffer(8);
var z = new Uint8ClampedArray(buffer, 1, 4);

// From an iterable
var iterable = (function* () {
  yield* [1, 2, 3];
})();
var uintc8 = new Uint8ClampedArray(iterable);
// Uint8ClampedArray[1, 2, 3]

ECMAScript 2027 LanguageSpecification
# sec-typedarray-objects

ECMAScript 2015 Uint8ClampedArray new new Uint8ClampedArray TypeError

js
var dv = Uint8ClampedArray([1, 2, 3]);
// TypeError: calling a builtin Uint8ClampedArray constructor
// without new is forbidden
js
var dv = new Uint8ClampedArray([1, 2, 3]);


Web Proxy Viewer  |  New URL  |  Original Page