FormData: values() method

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

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

The **FormData.values()** method returns an iterator which iterates through all values contained in the {{domxref("FormData")}}. The values are strings or {{domxref("Blob")}} objects.

توجه: 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).

Syntax

js-nolint
values()

Parameters

None.

Return value

An [iterator](/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) of {{domxref("FormData")}}'s values.

Examples

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

// Display the values
for (const value of formData.values()) {
  console.log(value);
}

The result is:

plain
value1
value2

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • Using FormData objects
  • {{HTMLElement("Form")}}