Created
July 16, 2022 01:39
-
-
Save ryochin/2f617d9d797d2f87f35db72d287ea4d7 to your computer and use it in GitHub Desktop.
TypeScript version of jQuery's serializeArray()
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
| // see also: https://barker.codes/blog/serialize-form-data-into-an-array-in-vanilla-js/ | |
| // NOTE: type FormDataEntryValue = File | string | |
| type SerializeArray = { [x: string]: FormDataEntryValue } | |
| const serializeArray = (form: HTMLFormElement): SerializeArray => { | |
| const result: SerializeArray = <SerializeArray>{} | |
| const formData: FormData = new FormData(form) | |
| formData.forEach((val: FormDataEntryValue, key: string) => result[key] = val) | |
| return result | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment