I have a dynamic elements as follows
<div class="pax_details">
<div class="adult_pax">
<input name="first_name_1">
<input name="last_name_1">
</div>
<div class="adult_pax">
<input name="first_name_2">
<input name="last_name_2">
</div>
</div>
<div class="pax_details">
<div class="adult_pax">
<input name="first_name_3">
<input name="last_name_3">
</div>
<div class="adult_pax">
<input name="first_name_4">
<input name="last_name_4">
</div>
</div>
I need to fetch all adults first name and last name into an array of objects using jquery
like
[[{"first_name":"Anish","last_name":"gopi"},{"first_name":"Vinay","last_name":"prasad"}]
[{"first_name":"Ananaya","last_name":"vital"},{"first_name":"Guru","last_name":"govind"}]]
What I tried so far?
let i = 0;
$('.pax_details').each(function(index,item){
$(item).find('.adult_pax').each(function(index,adult){
alert($(adult).find('input[name^="first_name_"]').val());
});
i++;
});