Back to Content

FormData: keys() method

files/en-us/web/api/formdata/keys/index.md

latest906 B
Original Source

{{APIRef("XMLHttpRequest API")}} {{AvailableInWorkers}}

The FormData.keys() method returns an iterator which iterates through all keys contained in the {{domxref("FormData")}}. The keys are strings.

Syntax

js-nolint
keys()

Parameters

None.

Return value

An iterator of {{domxref("FormData")}}'s keys.

Examples

js
const formData = new FormData();
formData.append("key1", "value1");
formData.append("key2", "value2");

// Display the keys
for (const key of formData.keys()) {
  console.log(key);
}

The result is:

plain
key1
key2

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also