What is the serializeArray() method in jQuery?

Overview

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.

Syntax

$(selector).serializeArray();

Parameters

This method doesn’t accept any parameters.

Return value

This method returns an array of objects. It will look something like this:

[
  {
    name: '',
    value: ''
  },
  {
    name: '',
    value: ''
  },
  ...
]

Example

Let’s look at an example of the serializeArray() method in the code snippet below:

Console

Explanation

In the HTML tab:

  • Line 4: We import the jQuery script.
  • Line 7: We create a form.
  • Line 9: We create an input element of the text type.
  • Line 13: We create an input element of the number type.
  • Line 16: We create a submit button.

In the JavaScript tab:

  • Line 3: We attach the click() method on the submit button.
  • Line 5: We use the serializeArray() method to create an array of objects of the form values.
  • Line 8: We print the array on the console.

Output

The serializeArray() method is invoked when we click the submit button, and the array is printed on the console.

New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources