Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all the values of input array element jquery [duplicate]

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

like image 801
user3707303 Avatar asked Jul 01 '14 06:07

user3707303


People also ask

How to get array of input values in JavaScript?

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.

How to check all elements in array in js?

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.

How to check if array is all true JavaScript?

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.


1 Answers

By Using map

var values = $("input[name='pname[]']")               .map(function(){return $(this).val();}).get(); 
like image 182
Mahendra Jella Avatar answered Sep 28 '22 05:09

Mahendra Jella