there are following input fields with datepicker class:
<input type="text" class="datepicker" value="" />
<input type="text" class="datepicker" value="" />
<input type="text" class="datepicker" value="2011-02-15" />
<input type="text" class="datepicker" value="2011-02-16" />
I need to create an array of dates, exclude blank values and return maximum value. Following code doesn't seem to exclude blank values:
var datelist = [];
$(".datepicker").each(function(i) {
if (this.value!="") {datelist[i] = this.value;}
});
datelist.sort();
datelist.reverse();
alert(datelist); //,,2011-02-16,2011-02-15
alert(datelist[0]); //undefined
What's the catch?