Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.