DOM Methods
FormData.set()
Replaces the first entry of that name and removes further entries with the same name. If absent, it appends a new entry. Useful when a field must have just one value. Example result: ["js"].
Formal Syntax & Structure
html syntaxhtml
data.set(name, value, filename?)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | Field name; matching is case-sensitive. |
| value | string | Blob | Value to store; non-Blob values are converted to strings. |
| filename | string | Optional filename when value is a Blob or File. |
Return Value
undefined
No return value.
Working Example
Example Snippethtml
<p> Result: <output id="result"></output></p><script> const result = document.getElementById("result"); (async () => { const data = new FormData(); data.append("tag", "html"); data.append("tag", "css"); data.set("tag", "js"); result.textContent = JSON.stringify(data.getAll("tag")); })().catch(error => { result.textContent = "Error: " + error.name; });</script>