I have a form with several textboxes. I want to serialize the whole form to json in a way that those text boxes remains in an array. I have the following html
<form id ="myform">
<input type="text" name="options[]"/>
<input type="text" name="options[]"/>
<input type="text" name="options[]"/>
<input type="text" name="options[]"/>
</form>
And I use jquery to convert it to json
JSON.stringify($("#myform").serializeArray());
This gives me the following:
{
"options[]":"Content of the last textbox"
}
but I want
{
"options":
{
"0":"value",
"1":"value",
"2":"value",
"3":"value",
}
}
How can I achieve this using javascript?