<!DOCTYPE html>
<html>
<head>
<title>Pushing all the values of an input class into an array jQuery</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
var myArray = [];
$('#subButton').on('click', function() {
$('.req').each(function() {
myArray.push($(this).val());
console.log(myArray);
});
});
});
</script>
<form id="iForm">
<input type="text" class="req" placeholder="Name">
<input type="text" placeholder="Surname">
<input type="text" placeholder="Email">
<input type="text" class="req" placeholder="City">
<input type="button" id="subButton" value="Registrati">
</form>
</body>
</html>