By using typed arrays, you can store arrays of these types:

Type Value Range Size(bytes)
Int8Array -128 to 127 1
Uint8Array 0 to 255 1
Uint8ClampedArray 0 to 255 1
Int16Array -32768 to 32767 2
Uint16Array 0 to 65535 2
Int32Array -2147483648 to 2147483647 4
Uint32Array 0 to 4294967295 4
Float32Array -3.4E38 to 3.4E38 4
Float64Array -1.8E308 to 1.8E308 8
BigInt64Array -2^63 to 2^63 - 1 8
BigUint64Array 0 to 2^64 - 1 8

Demo in Stack Snippets & JSFiddle

var array = new Uint8Array(100);
array[42] = 10;
console.log(array[42]);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Answer from Kendall Frey on Stack Overflow
🌐
Reddit
reddit.com › r/javascripttips › how to convert string to byte array in javascript?
r/JavaScriptTips on Reddit: How to Convert String to Byte Array in JavaScript?
May 1, 2023 - This object provides a view of an underlying ArrayBuffer object, which represents a fixed-length, contiguous block of memory. To convert a JavaScript string to a byte array, we can use the TextEncoder interface.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Typed_arrays
JavaScript typed arrays - JavaScript | MDN
They have "array" in their names, ... do with arrays — you cannot read or write to them directly. Instead, buffers are generic objects that just contain raw data. In order to access the memory represented by a buffer, you need to use a view. ... Allocate: As soon as a new buffer is created, a new memory span is allocated and initialized to 0. Copy: Using the slice() method, you can efficiently copy a portion of the memory without creating views to manually copy each byte...
🌐
Medium
medium.com › @julienetienne › different-types-of-arrays-in-javascript-and-when-to-use-them-77f7843b71de
Different Types of Arrays in JavaScript + When to Use Them | by Julien Etienne | Medium
February 8, 2024 - An ArrayBuffer is a “Byte Array”, which is an area of memory containing a group of contiguous (one after the other) bytes.
Find elsewhere
🌐
GitHub
gist.github.com › lihnux › 2aa4a6f5a9170974f6aa
Javascript Convert String to Byte Array · GitHub
Array.from("1111222223333444445556", , (x) => x.charCodeAt(0)) ... function unpack(str) { var bytes = []; for(var i = 0; i < str.length; i++) { var char = str.charCodeAt(i); bytes.push(char >>> 8); bytes.push(char & 0xFF); } return bytes; } this is the correct way to extract the bytes a JavaScript string is made of
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript store byte array
How to Store Byte Array in JavaScript | Delft Stack
February 2, 2024 - In addition, you can’t directly access elements in the ArrayBuffer object as we do in usual JavaScript arrays. It needs a separate view object to read/write. ... The above code will call the ArrayBuffer constructor to create a new ArrayBuffer instance with the specified byte length.
🌐
JavaScript.info
javascript.info › tutorial › binary data, files
ArrayBuffer, binary arrays
July 11, 2022 - Binary data in JavaScript is implemented in a non-standard way, compared to other languages. But when we sort things out, everything becomes fairly simple. The basic binary object is ArrayBuffer – a reference to a fixed-length contiguous memory area. ... This allocates a contiguous memory area of 16 bytes and pre-fills it with zeroes.
🌐
Programmingwithswift
programmingwithswift.com › how-to-convert-byte-array-to-string-with-javascript
How to convert a byte array to String with JavaScript
December 28, 2020 - In this tutorial I will show you how you can convert a byte array to a string using JavaScript. I was busy with a task recently that required me to do this, luckily, JavaScript makes this easy with the built in String.fromCharCode() function. Let's see how we can
🌐
GitHub
github.com › frida › frida › issues › 293
How can I create byte array in js? · Issue #293 · frida/frida
June 26, 2017 - I use frida to hook java application and I want to overload the following code of Java: void java_func(HttpURLConnection httpconne){ InputStream input = httpconne.getInputStream(); ByteArrayOutputStream baos = new byteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; while (( len = input.read(buffer)) > -1) { baos.write(buffer,0,len); } baos.flush(); }
Author   frida
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › TypedArray › byteLength
TypedArray.prototype.byteLength - JavaScript - MDN Web Docs
September 25, 2025 - const buffer = new ArrayBuffer(8); const uint8 = new Uint8Array(buffer); uint8.byteLength; // 8 (matches the byteLength of the buffer) const uint8newLength = new Uint8Array(buffer, 1, 5); uint8newLength.byteLength; // 5 (as specified when constructing the Uint8Array) const uint8offset = new Uint8Array(buffer, 2); uint8offset.byteLength; // 6 (due to the offset of the constructed Uint8Array) const buffer2 = new ArrayBuffer(16, { maxByteLength: 32 }); const uint8lengthTracking = new Uint8Array(buffer2, 4); uint8lengthTracking.byteLength; // 12 (16 - 4) buffer2.resize(20); uint8lengthTracking.byteLength; // 16 (20 - 4) buffer2.resize(3); uint8lengthTracking.byteLength; // 0 (viewed range is no longer valid)
🌐
Substack
alexanderobregon.substack.com › alexander obregon's substack › reading binary data in javascript with typed arrays and arraybuffer
Reading Binary Data in JavaScript with Typed Arrays and ArrayBuffer
June 25, 2025 - Everything starts with memory, and in JavaScript, ArrayBuffer is the block you use to hold raw bytes. It doesn’t carry any structure on its own. You decide how to read and write the contents by attaching typed views that shape those bytes into real values. The buffer gives you a fixed-size chunk, and once it’s set, the size doesn’t change.
🌐
Designcise
designcise.com › web › tutorial › how-to-convert-a-javascript-byte-array-to-a-string
How to Convert a JavaScript Byte Array to a String? - Designcise
April 9, 2023 - In JavaScript, you can convert an array of bytes to string by using the TextDecoder API with UTF-8 encoding, for example, in the following way: function fromBinaryArray(bytes) { const decoder = new TextDecoder('utf-8'); return decoder.decode(bytes); ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Response › bytes
Response: bytes() method - Web APIs - MDN Web Docs
November 7, 2025 - The checkSignature() method is defined below. This fetches a file at the given url, and uses response.bytes() to get its contents as a byte array. The initial bytes are then compared to the initial signature bytes of a number of common file types.
🌐
Dilshankelsen
dilshankelsen.com › convert-file-to-byte-array
How To Convert A File To A Byte Array | Dilshan Kelsen
JAVASCRIPTCopy · const inputNode = document.getElementById('upload_file') const selectedFile = inputNode.files[0] And for that you wish to first convert the file into a byte array. To start off, define an asynchronous function called getAsByteArray that returns it as such.
🌐
GitHub
github.com › gopherjs › gopherjs › issues › 667
what's the data type corresponding to byte array ([]byte) in javascript · Issue #667 · gopherjs/gopherjs
July 28, 2017 - what's the data type corresponding to byte array ([]byte) in javascript#667 · Copy link · fearblackcat · opened · on Jul 28, 2017 · Issue body actions · question is same to title. Is it array? I mean in front side web browser. Reactions are currently unavailable ·
Author   gopherjs
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Uint8Array
Uint8Array - JavaScript - MDN Web Docs
Populates this Uint8Array object with bytes from a hex-encoded string, returning an object indicating how many bytes were read and written.