There is such a function:
var getInfoForPrices = function (arg) { var dateIn = $(".date-in").val(); var dateOut = $(".date-out").val(); var roomsId = $('.collect-date .rooms-id').val(); var roomsCount = $('.collect-date .rooms-count').val(); var roomsIdArray = roomsId.split(","); var roomsCountArray = roomsCount.split(","); $('.collect-date .start-date').val(dateIn); $('.collect-date .end-date').val(dateOut); if (arg.hasClass('room-count')) { var currentRoomId = arg.attr('id').split('-')[1]; var currentRoomCount = arg.find('option:selected').val(); if($.inArray(currentRoomId, roomsIdArray) === -1){ roomsIdArray.push(currentRoomId); roomsCountArray.push(currentRoomCount); } else { var elPos = $.inArray(currentRoomId, roomsIdArray); roomsCountArray[elPos] = currentRoomCount; } $('.collect-date .rooms-id').val(roomsIdArray); $('.collect-date .rooms-count').val(roomsCountArray); } }; which serves to collect data and substitute them into hidden fields. The function is called when several fields change in another form:
$(".date-in, .date-out, .room-count").change(function () { getInfoForPrices($(this)); }); But it turns out that the first elements of the arrays are empty each time.

How to make sure that the first empty element is not entered into the array?