Response.prototype.arrayBuffer
Takes a Response stream and reads it to completion, returning the result as an ArrayBuffer
Syntax
response.arrayBuffer()Return Value
A Promise that resolves to an ArrayBuffer
Examples
const response = await fetch('/audio.mp3')
const buffer = await response.arrayBuffer()
console.log('Bytes:', buffer.byteLength)async function loadWasm(url: string) {
const res = await fetch(url)
const buffer = await res.arrayBuffer()
const module = await WebAssembly.compile(buffer)
return module
}const res = await fetch('/file.bin')
const buffer = await res.arrayBuffer()
const view = new Uint8Array(buffer)
console.log('First byte:', view[0])Understanding Response.prototype.arrayBuffer
The Response.prototype.arrayBuffer method in JavaScript takes a Response stream and reads it to completion, returning the result as an ArrayBuffer. It belongs to the Response object and is one of the most widely used methods for working with response values in modern JavaScript and TypeScript applications.
The method signature is response.arrayBuffer(). When called, it returns a promise that resolves to an arraybuffer. Understanding when and how to use arrayBuffer() helps you write more expressive, readable code.
Common use cases for Response.prototype.arrayBuffer include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like fetch-response-blob, fetch-response-text, fetch-response-json, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Response.prototype.arrayBuffer is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Response.prototype.blobTakes a Response stream and reads it to completion, returning the result as a Blob
Response.prototype.textTakes a Response stream and reads it to completion, returning the result as a string
Response.prototype.jsonTakes a Response stream and reads it to completion, parsing the result as JSON
More Response Methods
Other methods in the Response object
Related Tools
More Response Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.