jQuery serializeArray() creates an array of objects i.e. name and value pair by serializing one or more form elements or the form element itself.
jQuery serializeArray() method can act on a jQuery object which has selected individual form controls like <input>, <textarea>, and <select> etc.
Suppose, you have a following HTML:
<form action-xhr="#"> Name: <input type="text" name="name" value="John"><br> Age: <input type="text" name="age" value="30"><br> <input type="submit" name="submit" value="Submit" /> </form>
When using serializeArray() method as below:
var arr = $("form").serializeArray();
Results: name:John age:30
var arr = $("form").serializeArray(); var len = arr.length; var dataObj = {}; for (i=0; i<len; i++) { dataObj[arr[i].name] = arr[i].value; } console.log(dataObj['name']); // returns John console.log(dataObj['age']); // returns 30
In a world where digital presence is paramount, the question isn't whether you should do…
Over the years, people have experimented with various methods to maintain healthy and beautiful hair.…
Your brand more than developing an attractive and creative logo and infectious motto. It's the…
Introduction Are you someone who has suffered from a personal injury and want to file…
Operating from home has emerged as one of the most popular ways of doing jobs…
If the consequences of our society’s ever-growing debt are what worries you, then it is…