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 Web Docs
Creates a new non-resizable ArrayBuffer with the same byte content as this buffer, then detaches this buffer. In this example, we create a 8-byte buffer with an Int32Array view referring to the buffer:
🌐
Scala Documentation
docs.scala-lang.org › overviews › scala-book › arraybuffer-examples.html
The ArrayBuffer Class | Scala Book | Scala Documentation
You remove elements from an ArrayBuffer with the -= and --= methods: // remove one element nums -= 9 // remove multiple elements nums -= 7 -= 8 // remove multiple elements using another collection nums --= Array(5, 6) Here’s what all of those examples look like in the REPL:
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

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › ArrayBuffer › ArrayBuffer
ArrayBuffer() constructor - JavaScript - MDN Web Docs
October 30, 2025 - // Create an ArrayBuffer with a size in bytes const buffer = new ArrayBuffer(8); console.log(buffer.byteLength); // Expected output: 8
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Response › arrayBuffer
Response: arrayBuffer() method - Web APIs - MDN Web Docs
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"); }); };
🌐
WebPlatform
webplatform.github.io › docs › javascript › ArrayBuffer
ArrayBuffer · WebPlatform Docs
var req = new XMLHttpRequest(); req.open('GET', "http://www.example.com"); req.responseType = "arraybuffer"; req.send(); req.onreadystatechange = function () { if (req.readyState === 4) { var buffer = req.response; var dataview = new DataView(buffer); var ints = new Int32Array(buffer.byteLength / 4); for (var i = 0; i < ints.length; i++) { ints[i] = dataview.getInt32(i * 4); } alert(ints[10]); } }
🌐
JavaScripture
javascripture.com › ArrayBuffer
ArrayBuffer JavaScript API
Creates a new ArrayBuffer with a copy of the bytes of this between beginByte (inclusive) and endByte (exclusive). If endByte is not specified, this.byteLength is used.
🌐
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.
Find elsewhere
🌐
Tricentis
tabnine.com › home › products overview
Agentic Quality Engineering Platform - Tricentis
January 31, 2018 - Ship AI-generated code with confidence. The Tricentis Agentic Quality Engineering Platform unifies specialized AI agents under one governed control plane.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-arraybuffer-object
JavaScript ArrayBuffer Object - GeeksforGeeks
December 15, 2022 - Return value: It returns a new ArrayBuffer object of the specified size and the content is initialized to 0. Example: In this example, we will see the use of the Javascript ArrayBuffer() method.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-arraybuffer-constructor
JavaScript ArrayBuffer() Constructor | GeeksforGeeks
May 18, 2023 - Return value: It returns a new ArrayBuffer object of the specified size and the content is initialized to 0. Example 1: This example creates ArrayBufferobject with different parameters.
🌐
Telerik
telerik.com › blogs › array-buffers-javascript
Array Buffers in JavaScript
October 22, 2025 - Let’s manipulate the array buffer we created in the previous example (remember it is empty) using a typed array of Uint8Array, Int16Array and Float32Array. const buffer = new ArrayBuffer(8); //creates a buffer of 8 bytes
🌐
Uchicago
contest-server.cs.uchicago.edu › ref › JavaScript › developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › ArrayBuffer.html
ArrayBuffer
May 19, 2019 - Has the same functionality as ArrayBuffer.prototype.slice(). In this example, we create a 8-byte buffer with a Int32Array view referring to the buffer:
🌐
JavaScript.info
javascript.info › tutorial › binary data, files
ArrayBuffer, binary arrays
July 11, 2022 - So, the binary data in an ArrayBuffer of 16 bytes can be interpreted as 16 “tiny numbers”, or 8 bigger numbers (2 bytes each), or 4 even bigger (4 bytes each), or 2 floating-point values with high precision (8 bytes each).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Blob › arrayBuffer
Blob: arrayBuffer() method - Web APIs - MDN Web Docs
December 2, 2023 - The arrayBuffer() method of the Blob interface returns a Promise that resolves with the contents of the blob as binary data contained in an ArrayBuffer.
🌐
Medium
medium.com › @conboys111 › arraybuffer-vs-standard-arrays-when-and-why-should-you-use-it-cd2891394fab
ArrayBuffer vs Standard Arrays: When and Why Should You Use It? | by myHotTake | Medium
January 18, 2025 - For example, ArrayBuffer is often used when working with Web APIs like fetch for handling binary files or WebSockets for sending/receiving data.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Request › arrayBuffer
Request: arrayBuffer() method - Web APIs | MDN
November 7, 2025 - The arrayBuffer() method of the Request interface reads the request body and returns it as a promise that resolves with an ArrayBuffer.
🌐
Baeldung
baeldung.com › home › scala collections › guide to arraybuffer
Guide to ArrayBuffer | Baeldung on Scala
March 18, 2024 - The Scala ArrayBuffer is one of those. There are two main groups of collections in Scala: immutable and mutable collections. While the Scala community is biased towards the usage of immutable data structures, the standard lib also provides many mutable collections. One such example is the ArrayBuffer class which is very similar to normal Java Lists.
🌐
Mozilla Hacks
hacks.mozilla.org › home › articles › a cartoon intro to arraybuffers and sharedarraybuffers
A cartoon intro to ArrayBuffers and SharedArrayBuffers – Mozilla Hacks - the Web developer blog
June 14, 2017 - For example, if we get elements 0 & 1 from the Int8 view on this ArrayBuffer, it will give us different values than element 0 in the Uint16 view, even though they contain exactly the same bits.