FormData: get() method

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

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

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

The **get()** method of the {{domxref("FormData")}} interface returns the first value associated with a given key from within a FormData object. If you expect multiple values and want all of them, use the {{domxref("FormData.getAll()","getAll()")}} method instead.

Syntax

js-nolint
get(name)

Parameters

  • name
  • : A string representing the name of the key you want to retrieve.

Return value

A value whose key matches the specified name. Otherwise, [null](/en-US/docs/Web/JavaScript/Reference/Operators/null).

Examples

If we add two username values to a {{domxref("FormData")}} using {{domxref("FormData.append", "append()")}}:

js
formData.append("username", "Chris");
formData.append("username", "Bob");

The following get() method will only return the first username value:

js
formData.get("username"); // Returns "Chris"

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

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