Skip to content

Instantly share code, notes, and snippets.

@sscotth
Last active March 28, 2017 08:25
Show Gist options
  • Save sscotth/0dc6ba0541b0547b718814c950f4bfcb to your computer and use it in GitHub Desktop.
Save sscotth/0dc6ba0541b0547b718814c950f4bfcb to your computer and use it in GitHub Desktop.
Form serialization to object
[...new FormData(document.querySelector('form'))].reduce((o, [name, value]) => ({ ...o, [name]: value }), {})
$('form').serializeArray().reduce((o, { name, value }) => ({ ...o, [name]: value }), {})
[...document.querySelector('form')].filter(el => el.name).reduce((o, { name, value }) => ({ ...o, [name]: value }), {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment