Last active
August 25, 2019 13:02
-
-
Save Mamaduka/164bc6d17281aa0656dc208376ec6c69 to your computer and use it in GitHub Desktop.
Get form data as name => value pair in ES6.
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
const form = document.getElementById( 'acme-form' ); | |
// Checkboxe, select and radios are handled differently | |
const dataArray = Array | |
.from( form.elements ) | |
.filter( input => ( input.type === 'text' || input.type === 'textarea' ) ) | |
.map( input => { | |
return { [input.name] : input.value } | |
} ); | |
// Convert collected data array into object. | |
const data = Object.assing( ...dataArray ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment