Summary
The Uint8Array typed array represents an array of 8-bit unsigned integers. The contents are initialized to 0. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation).
Syntax
Uint8Array(length); Uint8Array(typedArray); Uint8Array(object); Uint8Array(buffer [, byteOffset [, length]]);
For more information about the constructor syntax and the parameters, see TypedArray.
Properties
-
Uint8Array.BYTES_PER_ELEMENT -
Returns a number value of the element size.
1in the case of anUint8Array. - Uint8Array.length
- Length property whose value is 3.
-
Uint8Array.name -
Returns the string value of the constructor name. In the case of the
Uint8Arraytype: "Uint8Array". -
Uint8Array.prototype - Prototype for the TypedArray objects.
Methods
- Uint8Array.from()
-
See
Array.from(). Not implemented, see bug 896608. - Uint8Array.of()
-
See
Array.of(). Not implemented, see bug 896608.
Uint8Array prototype
All Uint8Array objects inherit from %TypedArray%.prototype.
Properties
-
Uint8Array.prototype.constructor -
Returns the function that created an instance's prototype. This is the
Uint8Arrayconstructor by default. -
Uint8Array.prototype.bufferRead only -
Returns the
ArrayBufferreferenced by theUint8ArrayFixed at construction time and thus read only. -
Uint8Array.prototype.byteLengthRead only -
Returns the length (in bytes) of the
Uint8Arrayfrom the start of itsArrayBuffer. Fixed at construction time and thus read only. -
Uint8Array.prototype.byteOffsetRead only -
Returns the offset (in bytes) of the
Uint8Arrayfrom the start of itsArrayBuffer. Fixed at construction time and thus read only. -
Uint8Array.prototype.lengthRead only -
Returns the number of elements hold in the
Uint8Array. Fixed at construction time and thus read only.
Methods
-
Uint8Array.prototype.copyWithin() -
See
Array.prototype.copyWithin(). -
Uint8Array.prototype.move()Unimplemented -
Former non-standard version of
Uint8Array.prototype.copyWithin(). -
Uint8Array.prototype.set() -
Stores multiple values in the
Uint8Array, reading input values from a specified array. -
Uint8Array.prototype.subarray() -
Returns a new
Uint8Arrayfrom the given start and end element index.
Examples
// From a length var uint8 = new Uint8Array(2); uint8[0] = 42; console.log(uint8[0]); // 42 console.log(uint8.length); // 2 console.log(uint8.BYTES_PER_ELEMENT); // 1 // From an array var arr = new Uint8Array([21,31]); console.log(arr[1]); // 31 // From another TypedArray var x = new Uint8Array([21, 31]); var y = new Uint8Array(x); console.log(y[0]); // 21 // From an ArrayBuffer var buffer = new ArrayBuffer(8); var z = Uint8Array(buffer, 1, 4);
Specifications
| Specification | Status | Comment |
|---|---|---|
| Typed Array Specification | Obsolete | Superseded by ECMAScript 6. |
| ECMAScript 6 (ECMA-262) The definition of 'TypedArray constructors' in that specification. |
Draft | Initial definition in an ECMA standard. |
Browser compatibility
Help improve compatibility tables by filling out this 11 question survey.
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 7.0 | 4.0 (2) | 10 | 11.6 | 5.1 |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | 4.0 | (Yes) | 4.0 (2) | 10 | 11.6 | 4.2 |
See also
Document Tags and Contributors
Tags:
Contributors to this page: Sheppy, smirea, fscholz, Dikrib, yyss, markcaudill, LpH3, kscarfone, jyasskin, fusionchess, teoli, Nfroidure, mathphreak
Last updated by:
fscholz,