new FormData(form)
Collects named form values.
FormData reads form fields into a structured object that can be sent with fetch or inspected in JavaScript.
const formData = new FormData(form);
console.log(formData.get("title"));
JSON & Structured Data
FormData reads successful form controls by their name attributes. It works with text inputs, selects, checkboxes, files and more.
You can pass FormData directly as a fetch body for multipart form requests. You can also convert it with Object.fromEntries for simple text-only forms.
FormData can hold multiple values for the same name. Use getAll when repeated values matter.
Collects named form values.
Reads the first value for a field.
Reads every value for repeated fields.
Adds or replaces values programmatically.
Examples
<input name="title">
const formData = new FormData(form);
const title = formData.get("title");
<input id="title">
const formData = new FormData(form);
console.log(formData.get("title")); // null
Code patterns
These patterns focus on the data boundaries you will use constantly: JSON, URLs, forms, files, fetch objects and binary buffers.
Use get for one form value.
const formData = new FormData(form);
const title = formData.get("title");
Works well for simple text forms.
const data = Object.fromEntries(new FormData(form));
Use getAll for checkbox groups or repeated names.
const tags = formData.getAll("tag");
FormData can be used as a request body.
await fetch("/api/records", {
method: "POST",
body: new FormData(form)
});
Rules that matter
Structured data becomes reliable when every boundary is explicit: text to object, form to values, URL to parameters, response to JSON and bytes to meaning.
FormData reads names, not ids.
get only returns the first value.
The browser sets the boundary when sending FormData.
Object.fromEntries loses repeated values.
FormData does not prove values are correct.
File inputs return File objects.
Production thinking
FormData keeps form handling close to native browser behavior instead of manually querying every input.
Forms should keep labels, names and validation messages aligned so collected values match what users see.
Production form handling should validate FormData before sending or storing it.
Forms usually do not affect SEO directly, but accessible forms improve user experience and conversion.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Structured data is safe only when you know where it came from, what shape it has and what conversion happened before use.