Last active
January 20, 2021 19:17
-
-
Save bobdobbalina/79069104f62c7fa05ab0f1556fc1332d to your computer and use it in GitHub Desktop.
Javascript: Convert form data to json
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 formToObject = form => | |
Array.from(new FormData(form)).reduce( | |
(acc, [key, value]) => ({ | |
...acc, | |
[key]: value | |
}), | |
{} | |
); | |
formToObject(document.querySelector('form'); | |
// {"full-name":"Adrian Legaspi","email":"[email protected]","nickname":"ImLuyou"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment