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 Top answer 1 of 4
97
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
2 of 4
20
var array = new Uint8Array(100);
array[10] = 256;
array[10] === 0 // true
I verified in firefox and chrome, its really an array of bytes :
var array = new Uint8Array(1024*1024*50); // allocates 50MBytes
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › ArrayBuffer
ArrayBuffer - JavaScript - MDN Web Docs
It is an array of bytes, often referred to in other languages as a "byte array".
08:14
13. Javascript : Typed Arrays & Array Buffers - YouTube
15:52
Introduction to Typed Arrays in JavaScript | JavaScript Tutorial ...
- YouTube
JavaScript Type Arrays - The Bytes Per Element Property
12:33
javascript convert byte array to string geeksforgeeks - YouTube
01:44
Convert base64 string into byte array through javascript - YouTube
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Typed_arrays
JavaScript typed arrays - JavaScript | MDN
The DataView is a low-level interface that provides a getter/setter API to read and write arbitrary data to the buffer. This is useful when dealing with different types of data, for example. Typed array views are in the native byte-order (see Endianness) of your platform.
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 - A byte array is a contiguous block of memory that contains a sequence of bytes. Each byte in the array represents a numeric value between 0 and 255. Byte arrays are commonly used for low-level data manipulation and network communication.
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.
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 - The byteLength accessor property of TypedArray instances returns the length (in bytes) of this typed array.
JavaScript in Plain English
javascript.plainenglish.io › javascript-data-encoding-and-decoding-techniques-buffers-byte-arrays-dataview-binary-219d55b535a2
JavaScript Data Encoding and Decoding Techniques: Buffers, Byte arrays, DataView, binary, hexadecimal, and decimals. | by Varun Kukade | JavaScript in Plain English
May 4, 2024 - Now we can accept the byte array and convert it to an appropriate format to read the data. In JavaScript, unlike some other programming languages such as Java, bytes are not explicitly defined as a primitive data type. Instead, JavaScript has a generic number data type.
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
GeeksforGeeks
geeksforgeeks.org › how-to-convert-byte-array-to-string-in-javascript
JavaScript – Convert Byte Array to String | GeeksforGeeks
November 26, 2024 - The decode method converts the byte array to a string.
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 - It could be a file read from disk, a message sent over a WebSocket, or raw bytes from a Bluetooth device. Handling it the right way depends on tools built into the language. JavaScript gives you direct access to read and write binary through ArrayBuffer and typed array views like Uint8Array, which let you treat a block of raw bytes like a real data structure without extra libraries.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Response › bytes
Response: bytes() method - Web APIs - MDN Web Docs
September 4, 2026 - The bytes() method of the Response interface takes a Response stream and reads it to completion. It returns a promise that resolves with a Uint8Array.
Designcise
designcise.com › web › tutorial › how-to-convert-a-javascript-string-to-a-byte-array
How to Convert a JavaScript String to a Byte Array? - Designcise
April 9, 2023 - In JavaScript, you can convert a string to an array of bytes by using the TextEncoder API, for example, in the following way: function toBytesArray(str) { const encoder = new TextEncoder(); return encoder.encode(str); } console.log(toBytesA...