Skip to content

Instantly share code, notes, and snippets.

@jnettome
Created August 7, 2018 20:47
Show Gist options
  • Save jnettome/3fe0b2f5ee862b06c380a557ceabc3d1 to your computer and use it in GitHub Desktop.
Save jnettome/3fe0b2f5ee862b06c380a557ceabc3d1 to your computer and use it in GitHub Desktop.
html form values to json data
/**
* Retrieves input data from a form and returns it as a JSON object.
* @param {HTMLFormControlsCollection} elements the form elements
* @return {Object} form data as an object literal
*/
const formToJSON = elements => [].reduce.call(elements, (data, element) => {
data[element.name] = element.value;
return data;
}, {});
@jnettome
Copy link
Author

jnettome commented Aug 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment