The different constructors are:
new TypedArray(); // new in ES2017
new TypedArray(length);
new TypedArray(typedArray);
new TypedArray(object);
So when you do
new Uint8Array(255)
It will take it as a length. However you can pass an object (an array) instead which will be iterated to create the uint array:
new Uint8Array([255, 255, /*..*/]);
Answer from Jonas Wilms on Stack OverflowMDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Uint8Array
Uint8Array - JavaScript - MDN Web Docs
Creates a new Uint8Array object from a hex-encoded string.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Uint8Array › Uint8Array
Uint8Array() constructor - JavaScript - MDN Web Docs
July 10, 2025 - Note: Uint8Array() can only be constructed with new.
» npm install uint8arrays
Published: May 07, 2026
Version: 6.1.1
JavaScripture
javascripture.com › Uint8Array
Uint8Array JavaScript API
Returns a new Uint8Array with where each item is the result of calling callback on each item in this.
Top answer 1 of 3
16
The different constructors are:
new TypedArray(); // new in ES2017
new TypedArray(length);
new TypedArray(typedArray);
new TypedArray(object);
So when you do
new Uint8Array(255)
It will take it as a length. However you can pass an object (an array) instead which will be iterated to create the uint array:
new Uint8Array([255, 255, /*..*/]);
2 of 3
3
You need to add brackets to the list inside the Uint8Array argument
let myarr = new Uint8Array([1,2,3,...])
WebPlatform
webplatform.github.io › docs › javascript › Uint8Array
Uint8Array · WebPlatform Docs
uint8Array = new Uint8Array( length ); uintArray = new Uint8Array( array ); uintArray = new Uint8Array( buffer , byteOffset , length ); uint8Array · Required. The variable name to which the Uint8Array object is assigned. length · Specifies the length (in bytes) of the array.
Reality Ripple
udn.realityripple.com › docs › Web › JavaScript › Reference › Global_Objects › Uint8Array › Uint8Array
Uint8Array() constructor - JavaScript
// 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 = new Uint8Array(buffer, 1, 4); // From an iterable var iterable = function*(){ yield* [1,2,3]; }(); var uint8 = new Uint8Array(iterable); // Uint8Array[1, 2, 3]
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-uint8array-from-method
JavaScript Uint8Array.from() Method - GeeksforGeeks
January 9, 2024 - The Uint8Array.from() method in JavaScript is used to create a new Uint8Array from an array-like or iterable object.
JavaScript.info
javascript.info › tutorial › binary data, files
ArrayBuffer, binary arrays
July 11, 2022 - Please note, there’s no constructor called TypedArray, it’s just a common “umbrella” term to represent one of views over ArrayBuffer: Int8Array, Uint8Array and so on, the full list will soon follow. When you see something like new TypedArray, it means any of new Int8Array, new Uint8Array, etc.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Uint8Array › fromBase64
Uint8Array.fromBase64() - JavaScript - MDN Web Docs
The Uint8Array.fromBase64() static method creates a new Uint8Array object from a base64-encoded string.