Some important features of the jQuery serializeArray() method are:
- jQuery serializeArray() method creates a JavaScript array of objects.
- One can select one or more form elements, as it operates on a jQuery collection of forms and form controls.
- It serializes the form values.
Syntax:
$ (selector).serializeArray()
Example1:
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ var x = $("form").serializeArray(); $.each(x, function(i, field){ $("#results").append(field.name + ":" + field.value + " "); }); }); }); </script> </head> <body> <form action=""> First name: <input type="text" name="Mailid" value="test.com"><br> Last name: <input type="text" name="UserName" value="Jai"><br> </form> <button>Serialize</button> <div id="results"></div> </body> </html>