JavaScript FormData basics

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

Create new FormData(), append fields, then fetch(url, { method:"POST", body: fd }). Do not set Content-Type manually—the browser adds the boundary.

JavaScript Syntax

JavaScript
const fd = new FormData();
fd.append("title", "Note");
console.log(fd.has("title"));
console.log(fd.get("title"));
Try it Editor

How It Works

  1. append. Adds title.
  2. has/get. Confirms the value.

Examples

Example 1 — From a form element

In pages with a

.

JavaScript
console.log("new FormData(formElement) reads current fields");
Try it Editor

How It Works

  1. Pass the form DOM node to the constructor.

Frequently Asked Questions

Yes—append(name, file, filename) with a File/Blob.
The multipart boundary must match the body; the browser sets it when body is FormData.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful