You need to _.map()
the _.filter()
'ed array to format your dates accordingly.
Change your last line to:
var requiredData = _.map(
_.filter(testdata, function(data){
return data.date >= startDate && data.date <= endDate
}), function(nextData){
return nextData.date.getDate() + '/' + (nextData.date.getMonth()+1) + '/' + nextData.date.getFullYear().toString().split('').slice(2,4).join('');
}
);
EDIT: I thought that you wanted only the formatted date. My bad. Change your requireData assignment to:
var requiredData = _.map(_.filter(testdata, function(data){
return data.date >= startDate && data.date <= endDate
} // end of _.filter()'s handler function
),
function(nextData){
// create new field called 'formatted' in each object with formatted date
nextData.formatted = (nextData.date.getMonth()+1) + '/' + nextData.date.getDate() + '/' + nextData.date.getFullYear().toString().split('').slice(2,4).join('');
return nextData;
} // end of _.map()'s handler function
);
This will make requiredData
an array of object as you had originally with the addition that each one will have a property formatted
that will hold the date in format m/d/yy