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 Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_typed_uint8array.asp
JavaScript Uint8Array
const myArr = new Uint8Array(10); Try it Yourself » · Share Link Copied · Uint8Array array represents a typed array of 8-bit unsigned integers. Uint8Array contents are initialized to 0 by default. new Uint8Array(length) new Uint8Array(object) ...
🌐
GitHub
github.com › stdlib-js › array-uint8
GitHub - stdlib-js/array-uint8: Uint8Array. · GitHub
Creates a new typed array from an array-like object or an iterable. var arr = Uint8Array.from( [ 1, 2 ] ); // returns <Uint8Array>[ 1, 2 ]
Author: stdlib-js
🌐
npm
npmjs.com › package › uint8arrays
uint8arrays - npm
May 7, 2026 - import { alloc } from 'uint8arrays/alloc' const buf = alloc(100) Create a new Uint8Array.
      » 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.
🌐
Bun
bun.com › guides › binary data › arraybuffer to uint8array
Convert an ArrayBuffer to a Uint8Array | Bun Guides
const buffer = new ArrayBuffer(64); const arr = new Uint8Array(buffer, 0, 16); // view first 16 bytes
Find elsewhere
🌐
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]
Author: achingbrain
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-uint8array-of-method
JavaScript Uint8Array.of() Method | GeeksforGeeks
January 10, 2023 - 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.
🌐
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.
🌐
GitHub
github.com › sindresorhus › uint8array-extras
GitHub - sindresorhus/uint8array-extras: Useful utilities for working with Uint8Array (and Buffer) · GitHub
import {areUint8ArraysEqual} from 'uint8array-extras'; const a = new Uint8Array([1, 2, 3]); const b = new Uint8Array([1, 2, 3]); const c = new Uint8Array([4, 5, 6]); console.log(areUint8ArraysEqual(a, b)); //=> true console.log(areUint8ArraysEqual(a, c)); //=> false
Author: sindresorhus
🌐
Bun
bun.sh › guides › binary data › uint8array to arraybuffer
Convert a Uint8Array to an ArrayBuffer | Bun Guides
A Uint8Array is a typed array, a view over data in an underlying ArrayBuffer. The buffer property returns that ArrayBuffer. const arr = new Uint8Array(64); arr.buffer; // => ArrayBuffer(64)