Created
August 7, 2018 20:47
-
-
Save jnettome/3fe0b2f5ee862b06c380a557ceabc3d1 to your computer and use it in GitHub Desktop.
html form values to json data
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
/** | |
* 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; | |
}, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://code.lengstorf.com/get-form-values-as-json/