-
-
Save GaryStanton/04be7191c567ee4797c845da536644a4 to your computer and use it in GitHub Desktop.
Convert form data to JavaScript object with jQuery Ask Question
This file contains 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
function objectifyForm(formArray) { //serializeArray data function | |
var returnArray = {}; | |
for (var i = 0; i < formArray.length; i++){ | |
returnArray[formArray[i]['name']] = ((formArray[i]['name'] in returnArray) ? returnArray[formArray[i]['name']] + ',' + formArray[i]['value'] : formArray[i]['value']); | |
} | |
return returnArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to allow for multiple form fields with the same name. Currently returns a comma separated list, as a form POST would. May be preferable to return as an array for other uses.