Response.prototype.formData
Takes a Response stream and reads it to completion, returning the result as a FormData object
Syntax
response.formData()Return Value
A Promise that resolves to a FormData object
Examples
const response = await fetch('/api/form')
const formData = await response.formData()
console.log(formData.get('name'))const form = document.querySelector('form') as HTMLFormElement
const data = new FormData(form)
const res = await fetch('/api/submit', { method: 'POST', body: data })
const result = await res.formData()
console.log('Server response:', result.get('status'))async function parseMultipart(response: Response) {
const fd = await response.formData()
const entries: Record<string, FormDataEntryValue> = {}
fd.forEach((value, key) => { entries[key] = value })
return entries
}Understanding Response.prototype.formData
The Response.prototype.formData method in JavaScript takes a Response stream and reads it to completion, returning the result as a FormData object. 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.formData(). When called, it returns a promise that resolves to a formdata object. Understanding when and how to use formData() helps you write more expressive, readable code.
Common use cases for Response.prototype.formData include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like fetch-response-json, fetch-response-text, fetch-formdata-constructor, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Response.prototype.formData 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.jsonTakes a Response stream and reads it to completion, parsing the result as JSON
Response.prototype.textTakes a Response stream and reads it to completion, returning the result as a string
FormDataCreates a new FormData object optionally pre-populated with the key/value pairs from an HTML form
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.