---
title: "Convert form data to JS object with jQuery"  
description: "Convert form data to JS object with jQuery"  
author: "Anonymous User"  
published: 2013-05-29  
updated: 2013-05-29  
canonical: https://www.mindstick.com/forum/925/convert-form-data-to-js-object-with-jquery  
category: "json"  
tags: ["json"]  
reading_time: 1 minute  

---

# Convert form data to JS object with jQuery

Hi [Developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs),\
How do I [convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) all [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) of my [form](https://www.mindstick.com/forum/6/multi-form-mfc-application) to a JS object?\
I'd like to have some way of automatically [building](https://www.mindstick.com/blog/23088/which-tonewood-is-suitable-for-building-a-guitar) a JS object from my form, without having to loop over each element. I do not want a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp), as returned by \
$('#formid').serialize();, nor do I want the [map](https://yourviews.mindstick.com/view/81351/nepal-parliament-s-approves-new-controversial-map-india-rejects-it-but) returned by $('#formid').serializeArray();\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Ankita,\
serializeArray already does exactly that, you just need to massage the data into your required format:**\****Try as following**\

```
$.fn.serializeObject = function(){    var o = {};    var a = this.serializeArray();    $.each(a, function() {        if (o[this.name] !== undefined) {            if (!o[this.name].push) {                o[this.name] = [o[this.name]];            }            o[this.name].push(this.value || '');        } else {            o[this.name] = this.value || '';        }    });    return o;};
```

\


---

Original Source: https://www.mindstick.com/forum/925/convert-form-data-to-js-object-with-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
