Skip to content

docs(WebAPI): call out duplicate keys on FormData iteration methods - #45584

Open
MeGaurav4 wants to merge 2 commits into
mdn:mainfrom
MeGaurav4:fix/formdata-dupe-keys
Open

docs(WebAPI): call out duplicate keys on FormData iteration methods#45584
MeGaurav4 wants to merge 2 commits into
mdn:mainfrom
MeGaurav4:fix/formdata-dupe-keys

Conversation

@MeGaurav4

Copy link
Copy Markdown
Contributor

The issue: a form can hold several elements sharing one name, so FormData iteration can yield the same key many times. Readers coming from Map reasonably assume unique keys, and code like new Map(fd) silently drops values. None of the three iteration pages said keys may repeat.

What I changed, per page:

  • keys(): a Note that keys are not necessarily unique, pointing at getAll() for every value of a key and get() for the first value only.
  • entries(): the same callout, worded for key/value pairs.
  • values(): the same callout, worded for values sharing one key.

I used the two-argument domxref form the get() page already uses, and kept each note to one paragraph right after the intro so the pages read the same as before. Only these three method pages change; examples, front matter, and everything else are untouched. I left the top-level FormData() constructor page alone to keep this small, but I can follow up there if reviewers want it.

Closes #45582

Verification

  • Read all three pages and checked the note wording against the issue's duplicate-name example
  • Checked the get()/getAll() targets exist and the domxref form matches existing usage on the get() page
  • No trailing whitespace; no front-matter changes

Signed-off-by: MeGaurav4 <gaurav3.141592@gmail.com>
@MeGaurav4
MeGaurav4 requested a review from a team as a code owner September 9, 2026 04:46
@MeGaurav4
MeGaurav4 requested review from sideshowbarker and removed request for a team September 9, 2026 04:46
@github-actions github-actions Bot added Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed labels Sep 9, 2026

The **`FormData.entries()`** method returns an [iterator](/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) which iterates through all key/value pairs contained in the {{domxref("FormData")}}. The key of each pair is a string, and the value is either a string or a {{domxref("Blob")}}.

> **Note:** Unlike [`Map`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) entries, `FormData` entries are not necessarily unique by key. A form can contain multiple elements with the same name, so the same key may appear in more than one pair while iterating. To retrieve all values associated with a single key, use the {{domxref("FormData.getAll()", "getAll()")}} method (or {{domxref("FormData.get()", "get()")}} for only the first value).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[markdownlint] reported by reviewdog 🐶
error search-replace Custom rule [gfm-alert: Use the GFM syntax: https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Howto/Markdown_in_MDN#notes_warnings_and_callouts] [Context: "column: 1 text:'> Note:'"]


The **`FormData.keys()`** method returns an [iterator](/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) which iterates through all keys contained in the {{domxref("FormData")}}. The keys are strings.

> **Note:** Unlike [`Map`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) keys, `FormData` keys are not necessarily unique. A form can contain multiple elements with the same name, so the same key may appear more than once while iterating. To retrieve all values associated with a single key, use the {{domxref("FormData.getAll()", "getAll()")}} method (or {{domxref("FormData.get()", "get()")}} for only the first value).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[markdownlint] reported by reviewdog 🐶
error search-replace Custom rule [gfm-alert: Use the GFM syntax: https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Howto/Markdown_in_MDN#notes_warnings_and_callouts] [Context: "column: 1 text:'> Note:'"]


The **`FormData.values()`** method returns an [iterator](/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) which iterates through all values contained in the {{domxref("FormData")}}. The values are strings or {{domxref("Blob")}} objects.

> **Note:** `FormData` keys are not necessarily unique. A form can contain multiple elements with the same name, so values sharing one key each appear while iterating. To retrieve all values associated with a single key, use the {{domxref("FormData.getAll()", "getAll()")}} method (or {{domxref("FormData.get()", "get()")}} for only the first value).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[markdownlint] reported by reviewdog 🐶
error search-replace Custom rule [gfm-alert: Use the GFM syntax: https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Howto/Markdown_in_MDN#notes_warnings_and_callouts] [Context: "column: 1 text:'> Note:'"]

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Preview URLs (3 pages)

(comment last updated: 2026-09-09 04:56:03)

Signed-off-by: MeGaurav4 <gaurav3.141592@gmail.com>
@Josh-Cena
Josh-Cena requested a review from Rob--W September 9, 2026 06:21
The **`FormData.entries()`** method returns an [iterator](/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) which iterates through all key/value pairs contained in the {{domxref("FormData")}}. The key of each pair is a string, and the value is either a string or a {{domxref("Blob")}}.

> [!NOTE]
> Unlike [`Map`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) entries, `FormData` entries are not necessarily unique by key. A form can contain multiple elements with the same name, so the same key may appear in more than one pair while iterating. To retrieve all values associated with a single key, use the {{domxref("FormData.getAll()", "getAll()")}} method (or {{domxref("FormData.get()", "get()")}} for only the first value).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entries method provides key-value pairs, so prescribing the use of get or getAll may be confusing.

I suggest dropping them; an explicit mention warning about the disconnect between the value and get() could make sense for clarity. For example, something like this:

Suggested change
> Unlike [`Map`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) entries, `FormData` entries are not necessarily unique by key. A form can contain multiple elements with the same name, so the same key may appear in more than one pair while iterating. To retrieve all values associated with a single key, use the {{domxref("FormData.getAll()", "getAll()")}} method (or {{domxref("FormData.get()", "get()")}} for only the first value).
> Unlike [`Map`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) entries, `FormData` entries are not necessarily unique by key. A form can contain multiple elements with the same name, so the same key may appear in more than one pair while iterating. Past the first entry, the value may differ from the return value of {{domxref("FormData.get()", "get()")}} which returns the first value associated with the key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FormData and its iterable methods (keys, entries, values) should mention possibility of duplicate keys

3 participants