Basically ArrayBuffer is used to keep binary data. It can be the binary data of an image for example.

In other languages buffers are proved very useful. Yes, of course it is a little more difficult to understand/use than other data types.

ArrayBuffer can be used to get data of jpg image (RGB bytes) and produce a png out of it by adding alpha byte (i.e. RGBA).

Mozilla site has given a small use of ArrayBuffer here

Working with complex data structures

By combining a single buffer with multiple views of different types, starting at different offsets into the buffer, you can interact with data objects containing multiple data types. This lets you, for example, interact with complex data structures from WebGL, data files, or C structures you need to use while using js-ctypes.

Consider this C structure:

struct someStruct {  
  unsigned long id;  
  char username[16];  
  float amountDue;  
};  

You can access a buffer containing data in this format like this:

var buffer = new ArrayBuffer(24);  
  
// ... read the data into the buffer ...  
  
var idView = new Uint32Array(buffer, 0, 1);  
var usernameView = new Uint8Array(buffer, 4, 16);  
var amountDueView = new Float32Array(buffer, 20, 1);  

Then you can access, for example, the amount due with amountDueView[0].

Note: The data structure alignment in a C structure is platform-dependent. Take precautions and considerations for these padding differences.

Answer from Imdad on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › ArrayBuffer
ArrayBuffer - JavaScript | MDN
It is an array of bytes, often referred to in other languages as a "byte array". You cannot directly manipulate the contents of an ArrayBuffer; instead, you create one of the typed array objects or a DataView object which represents the buffer in a specific format, and use that to read and ...
Top answer
1 of 4
91

Basically ArrayBuffer is used to keep binary data. It can be the binary data of an image for example.

In other languages buffers are proved very useful. Yes, of course it is a little more difficult to understand/use than other data types.

ArrayBuffer can be used to get data of jpg image (RGB bytes) and produce a png out of it by adding alpha byte (i.e. RGBA).

Mozilla site has given a small use of ArrayBuffer here

Working with complex data structures

By combining a single buffer with multiple views of different types, starting at different offsets into the buffer, you can interact with data objects containing multiple data types. This lets you, for example, interact with complex data structures from WebGL, data files, or C structures you need to use while using js-ctypes.

Consider this C structure:

struct someStruct {  
  unsigned long id;  
  char username[16];  
  float amountDue;  
};  

You can access a buffer containing data in this format like this:

var buffer = new ArrayBuffer(24);  
  
// ... read the data into the buffer ...  
  
var idView = new Uint32Array(buffer, 0, 1);  
var usernameView = new Uint8Array(buffer, 4, 16);  
var amountDueView = new Float32Array(buffer, 20, 1);  

Then you can access, for example, the amount due with amountDueView[0].

Note: The data structure alignment in a C structure is platform-dependent. Take precautions and considerations for these padding differences.

2 of 4
11

An ArrayBuffer is a chunk of binary data in RAM. There are a few ways to "open" an ArrayBuffer for reading and writing:

  • Typed arrays, such as Uint16Array, can read and write the buffer by treating it as an array of integers. They don't let you control endianness; it uses the CPU's preferred endianness. Uint8Array is useful for controlling individual bytes (copying, slicing, etc).

  • DataView is not as simple, but it gives you more control. It lets you choose the endianness, integer size, and byte index (e.g. you can access a 32 bit integer at an index that's not divisible by 32 bits). These things can be specified each time you read and write an integer with the same DataView.

More info: https://javascript.info/arraybuffer-binary-arrays

🌐
W3Schools
w3schools.com › jS › js_arraybuffers.asp
JavaScript Array Buffer
An ArrayBuffer is fixed a block of memory, often used to store typed arrays.
🌐
Telerik
telerik.com › blogs › array-buffers-javascript
Array Buffers in JavaScript
October 22, 2025 - In JavaScript, an ArrayBuffer is defined as an object that represents a generic, fixed-length raw binary data buffer. It allows you to work with binary data directly without worrying about character encoding.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Response › arrayBuffer
Response: arrayBuffer() method - Web APIs | MDN
November 7, 2025 - function getData() { const audioCtx = new AudioContext(); return fetch("viper.ogg") .then((response) => { if (!response.ok) { throw new Error(`HTTP error, status = ${response.status}`); } return response.arrayBuffer(); }) .then((buffer) => audioCtx.decodeAudioData(buffer)) .then((decodedData) => { const source = new AudioBufferSourceNode(audioCtx); source.buffer = decodedData; source.connect(audioCtx.destination); return source; }); } // wire up buttons to stop and play audio play.onclick = () => { getData().then((source) => { source.start(0); play.setAttribute("disabled", "disabled"); }); };
🌐
Medium
dev-aditya.medium.com › buffer-arraybuffer-float64array-in-node-js-ef68c112d905
Buffer, ArrayBuffer, Float64Array in Node.js | by Aditya Yadav | Medium
September 29, 2024 - ArrayBuffer: More generic, requiring views (Typed Arrays) to manipulate data. Web APIs: Fetching and processing binary data (e.g., images, audio). Web Workers: Sharing data between threads.
Find elsewhere
🌐
GitHub
github.com › stdlib-js › array-buffer
GitHub - stdlib-js/array-buffer: ArrayBuffer. · GitHub
Returns an ArrayBuffer having a specified number of bytes.
Author   stdlib-js
🌐
Reddit
reddit.com › r/learnprogramming › [javascript] what is an arraybuffer?
r/learnprogramming on Reddit: [JavaScript] What is an ArrayBuffer?
December 16, 2017 -

Hello,

I am trying to learn more about websockets, and to practice I’ve been reverse-engineering the communications between the client and server for basic html games.

For the super simple ones, it’s really easy — the client and server just send each other 8-9 element long arrays with information such as “x position” and “y position” for every nearby object.

But recently I tried this method with a more complex game (diep.io) and I’ve encountered some problems. After I found the right websocket (which took a while — there are many decoys), the data I get is just an “ArrayBuffer”, and I have no idea what this is.

When I see in the console: ArrayBuffer(1) or some other number, does this mean there is only one element in the array? How do I access this data? I’ve tried solutions online but nothing can reliably convert this messy data format into a simple array. It seems like the usual problem is that my array contains data a specific function does not expect and I get an offset error.

Thanks for the help!

🌐
JavaScript.info
javascript.info › tutorial › binary data, files
ArrayBuffer, binary arrays
Binary data in JavaScript is ... becomes fairly simple. The basic binary object is ArrayBuffer – a reference to a fixed-length contiguous memory area....
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-arraybuffer-reference
JavaScript ArrayBuffer Reference - GeeksforGeeks
July 23, 2025 - JavaScript ArrayBuffer Properties: A JavaScript property is a member of an object that associates a key with a value.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-arraybuffer-constructor
JavaScript ArrayBuffer() Constructor - GeeksforGeeks
July 11, 2025 - JavaScript ArrayBuffer Constructor is used to create a new ArrayBuffer object. ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. This object can only be created with the new keyword.
🌐
DEV Community
dev.to › dharamgfx › mastering-javascript-arraybuffer-a-comprehensive-guide-1d5h
🚀 Mastering JavaScript ArrayBuffer: A Comprehensive Guide - DEV Community
June 3, 2024 - The ArrayBuffer is a core part of JavaScript's low-level binary data manipulation capabilities. It represents a fixed-length raw binary data buffer.
🌐
Loune
loune.net › 2011 › 05 › javascript-arraybuffer-binary-handling-in-javascript
Javascript ArrayBuffer – Binary handling in javascript | Playing on the frontier
The ArrayBuffer allows you to allocate a opaque chunk of memory. To manipulate the buffer, we have to “cast” or map the array to a Typed Array. There are various typed arrays such as Int16Array, Float32Array, but the one that interests us is probably Uint8Array, allowing us to view our ...
🌐
Reality Ripple
udn.realityripple.com › docs › Web › JavaScript › Reference › Global_Objects › ArrayBuffer
ArrayBuffer - JavaScript
It is an array of bytes, often referred to in other languages as a "byte array".You cannot directly manipulate the contents of an ArrayBuffer; instead, you create one of the typed array objects or a DataView object which represents the buffer in a specific format, and use that to read and write the contents of the buffer.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › ArrayBuffer › slice
ArrayBuffer.prototype.slice() - JavaScript | MDN
July 10, 2025 - // Create an ArrayBuffer with a size in bytes const buffer = new ArrayBuffer(16); const int32View = new Int32Array(buffer); // Produces Int32Array [0, 0, 0, 0] int32View[1] = 42; const sliced = new Int32Array(buffer.slice(4, 12)); // Produces Int32Array [42, 0] console.log(sliced[0]); // Expected output: 42
🌐
GitHub
gist.github.com › miguelmota › 5b06ae5698877322d0ca
Node.js Buffer to ArrayBuffer · GitHub
Node.js Buffer to ArrayBuffer. GitHub Gist: instantly share code, notes, and snippets.
🌐
DEV Community
dev.to › ollaworld › arraybuffer-in-js-56ja
ArrayBuffer in JS - DEV Community
December 8, 2024 - The ArrayBuffer() constructor creates ArrayBuffer objects. ... When constructing an Array Buffer, the JavaScript engine requests a block of bytes from the System’s Memory. This allocation occurs in the heap, a region of memory used for dynamically allocated objects in most programming languages.