Skip to content

Instantly share code, notes, and snippets.

@sbussard
Created April 4, 2018 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbussard/225d8cc0e663b7f44409915e68d145a9 to your computer and use it in GitHub Desktop.
Save sbussard/225d8cc0e663b7f44409915e68d145a9 to your computer and use it in GitHub Desktop.
// given a form element
// get its children that have a name attribute
// map to { name, value } objects
// reduce individual into one { [name]: value } object
export default formElement => Array.from(formElement.querySelectorAll('[name]'))
.map(({ name, value }) => ({ name, value }))
.reduce((current, item) => ({ ...current, [item.name]: item.value }), {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment