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
var input = document. getElementsByName('array[]'); The document. getElementsByName() method is used to return all the values stored under a particular name and thus making input variable an array indexed from 0 to number of inputs.
The every() method executes a function for each array element. The every() method returns true if the function returns true for all elements. The every() method returns false if the function returns false for one element. The every() method does not execute the function for empty elements.
To check if all of the values in an array are equal to true , use the every() method to iterate over the array and compare each value to true , e.g. arr. every(value => value === true) . The every method will return true if the condition is met for all array elements.
By Using map
var values = $("input[name='pname[]']") .map(function(){return $(this).val();}).get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With