I am using a Bootstrap DatePicker so user can select the dates and at the back end, the selected dates will be stored in an array.
Whenever I select the dates, the javascript code .push()
is used to capture the selected dates and append the selected dates in the array.
I believe this is the correct format for an array right?
DateSelected = ["April 1, 2021", "April 2, 2021", "April 3, 2021", "April 4, 2021"]
BUT what is happening is this:
DateSelected = ["April 1, 2021, April 2, 2021, April 3, 2021, April 4, 2021"]
So what happening here is its as if the array contains ONE (1) entry only whenever I console.log(DateSelected.length)
. It should suppose to return FOUR (4) since I selected 4 dates.
Here's my code:
Bootstrap Date Picker
$('.datepicker').datepicker({
multidate: true,
toggleActive: true
}).on('changeDate', function(e){
$('#dt_due').val(
$('.datepicker').datepicker('getFormattedDate')
);
});
Javascript/ jQuery
var DateInsured = [];
DateSelected.push($('#dt_due').val());
console.log(DateSelected)
console.log(DateSelected.length)
Here's a screenshot of the Google Chrome Console