How to get all the values of input array element jquery

user3707303 picture user3707303 · Jul 1, 2014 · Viewed 137k times · Source

Here is my html input elements

<input type="text" name="pname[]" value="" />
<input type="text" name="pname[]" value="" />
<input type="text" name="pname[]" value="" />
<input type="text" name="pname[]" value="" />
<input type="text" name="pname[]" value="" />
<input type="text" name="pname[]" value="" />

How can I get all the values of pname array using Jquery

Answer

Lead Developer picture Lead Developer · Jul 1, 2014

By Using map

var values = $("input[name='pname[]']")
              .map(function(){return $(this).val();}).get();