Search code examples
jqueryserializearray

jQuery serializeArray() add another value on top for passing to Ajax


I'm doing the following:

var data = $(form).serializeArray();
// Now I want to  add another value on this data
data.username = 'this is username';

I want to know how can I add another value after doing serializeArray(). I tried all the things I know, but nothing is getting it to work. any ideas pls.


Solution

  • try

    data[data.length] = { name: "username", value: "The Username" };