javascript - how can i get all input fields values to an array in jquery? -


this question has answer here:

how can input fields values array in jquery?

please see codes bellow:

<input type="text" name="a" value="a" /> <input type="text" name="b" value="hello" /> <input type="text" name="c" value="world" />  <script type="text/javascript">     function get_fields_values(){          // code         var arr=[];         $.each($("input"),function(i,n){             arr.push(n.value)         });          return arr;          // there jquery method fields values array?         // $('input').xxx() ?     } </script> 

try use .map() along .get() accomplish task,

var arr = $("input").map(function(){ return this.value; }).get(); 

full code be,

function get_fields_values(){     return $("input").map(function(){ return this.value; }).get(); } 

demo


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -