Why do we keep rewriting libraries like this? We were writing the exact same thing at one of my previous jobs back in 2010.
1. I cannot put the values of one object inside the other unless they come under the same parent.
2. Arrays in my case can be created in one go and you need not specify the array indexes hard coded in the html itself.
3. In my case some inputs were not inside any forms. This library mandates that it should be so it did not work for me.
I understand my code will be far less sophisticated but I made it to solve a problem and learn javascript as well. I did and wanted to see how many others face the same problem and can use it.
Here is a list of even more sophisticated libraries that might help you as well
https://www.npmjs.com/search?q=form+serialize
Someone already posted this link earlier here.