Home >>jQuery Tutorial >jQuery serializeArray() Method

jQuery serializeArray() Method

jQuery serializeArray() Method

jQuery serializeArray() method in jQuery is used to creates an array of objects (name and value) by serializing form values (like input and/or text area).

Syntax:
$(selector).serializeArray()
Here is an Example of jQuery serializeArray() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").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="FirstName" value="Phptpoint"><br>
Last name: <input type="text" name="LastName" value="Training"><br>
</form><br>
<button class="btn1">Click me to Serialize form values</button>
<div id="results"></div>
</body>
</html>

Output:
First name:
Last name:


No Sidebar ads