Last active
January 22, 2022 13:34
-
-
Save monochromer/529756ed2cbc5a06a6ff85cfacbd0249 to your computer and use it in GitHub Desktop.
Serialize `FormData` to JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://jakearchibald.com/2021/encoding-data-for-post-requests/ | |
| function formToObject(formData) { | |
| return Object.fromEntries( | |
| [...new Set(formData.keys())] | |
| .map((key) => [key, formData.getAll(key)]), | |
| ); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment