The serializeArray()
method is a built-in method in jQuery that creates an array of objects by serializing the entire form data or specific form elements.
$(selector).serializeArray();
This method doesn’t accept any parameters.
This method returns an array of objects. It will look something like this:
[
{
name: '',
value: ''
},
{
name: '',
value: ''
},
...
]
Let’s look at an example of the serializeArray()
method in the code snippet below:
In the HTML tab:
jQuery
script.form
.input
element of the text
type.input
element of the number
type.submit
button.In the JavaScript tab:
click()
method on the submit
button.serializeArray()
method to create an array of objects of the form values.The serializeArray()
method is invoked when we click the submit button, and the array is printed on the console.