javascript - how can i get all input fields values to an array in jquery? -
this question has answer here:
- jquery. how load inputs values array? 2 answers
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(); } 
Comments
Post a Comment