0

When I use .serializeArray(), my data looks like:

[ Object { Name="Name", Value="MyName" }, Object { Name="Age", Value="15"} ]

But I want it to look like:

{ Name: "MyName", Age: 15 }

What do I need to do?

My form:

<form id="newUser">
<input id="Name" name="Name" />
<input id="Age" name="Age" />
<input type="submit" />
</form>
5
  • Why do you need it to be in that format? Commented Jul 5, 2011 at 22:23
  • 1
    possible duplicate of Serialize form to JSON with jQuery Commented Jul 5, 2011 at 22:26
  • backbone.js requires it to be like tha. Commented Jul 5, 2011 at 22:26
  • That solved my problem, can you delete this question please? Commented Jul 6, 2011 at 0:39
  • 1
    You should be able to delete or close the question yourself. There should be some controls for that below the post (near link | edit etc). Commented Jul 6, 2011 at 1:03

1 Answer 1

1

You could write a bit of code which takes the first format and then converts it into the other. Just have it loop over the array and take Name as a key in the object, and Value as the value for the key and assign each pair into a single object.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.