I have a form and would like to append the contents of it to an existing array.
I am using JSON.stringify( $('#myForm').serializeObject() )
to convert my form elements into json
objects.
The form has user info that i would like to append into myArr
then append this list into an existing array. myArr
is populating fine, its just appending that into existingJsonArray
i seem to be having problems with.
I saw this but since JSON.stringify
creates the full json array would i need to knock out the [{
and }]
?
Is this the correct approach?
var existingJsonArray = []; var myArr = []; myArr.unshift( JSON.stringify( $('#myForm').serializeObject() ) ); existingJsonArray.unshift(myArr);
JSON.stringify
does not create an object, but a string from an object.JSON.parse
?$('#myForm').serializeObject()
already returns object.