Skip to content

Instantly share code, notes, and snippets.

@codepainkiller
Last active February 4, 2016 15:16
Show Gist options
  • Save codepainkiller/f2d53f7d2fe6c9ba17ee to your computer and use it in GitHub Desktop.
Save codepainkiller/f2d53f7d2fe6c9ba17ee to your computer and use it in GitHub Desktop.
Jquery - Convert Form to Object
var myForm = $('#myForm');
console.log(formToObject(myForm));
function formToObject(form) {
var arrayForm = $(form).serializeArray();
var objectForm = {};
arrayForm.forEach(function (obj, index) {
objectForm[obj.name] = obj.value;
});
return objectForm;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment