Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

FormData — building and inspecting form data

FormData stores ordered name–value pairs, including repeated names. Learn the difference between append() and set(), how to iterate with entries(), and how to send the data using fetch().

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

const data = new FormData();
data.append(name, value);
data.set(name, value);
data.set(name, blob, filename);
for (const [name, value] of data.entries()) { /* ... */ }

FormData is a Web API interface, not part of ECMAScript itself. It stores an ordered list of name–value pairs; names may repeat. Values are strings or File objects. You can supply a Blob, which is stored as a file. Other values undergo Web IDL string conversion. Passing a Symbol as the value to append() or set() throws a TypeError during that conversion; no string is stored.

append(name, value) adds an entry while keeping earlier entries with the same name. FormData.set, called as data.set(name, value), replaces the first matching entry and removes the remaining entries with that name. If the name does not exist, it appends an entry. For a Blob, you can supply a third argument, filename.

FormData.entries, called as data.entries(), returns an iterator of [name, value] pairs in entry order. In the example, set("tag", "api") leaves one tag entry in the first entry's position, so it appears before name. This is not a plain object: converting it to an object will not preserve multiple values under the same name.

When sending it with fetch(url, { method: "POST", body: data }), do not manually set the Content-Type header: the browser creates multipart/form-data with a matching boundary parameter. The example sends no request. Check API availability in the target browser; the presence of Node 24 in a repository does not establish browser support.

Examples

const data = new FormData();
data.append("tag", "javascript");
data.append("tag", "web");
data.set("name", "Ada");
data.set("tag", "api");

for (const [name, value] of data.entries()) {
  console.log(`${name}=${value}`);
}

Result

tag=api
name=Ada

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources