0

I'm working on a site using the MEAN stack, I've got a helper js function which was working fine but now is giving me ReferenceError errors. I know this isn't elegant but this is my function:

module.exports.formatDatePickerDate = function(dt) {
if( dt !== undefined ) {
var ys = dt[date][year];
var ms = '0' + dt[date][month].slice(-2);
var ds = '0' + dt[date][day].slice(-2);
var cs = ys + '-' + ms + '-' + ds;
console.log(cs);
return cs;
} else {
return undefined;
}
}

it's being passed an object that looks like this:

{ date: { year: 2017, month: 7, day: 20 }, jsdate: '2017-07-19T23:00:00.000Z', formatted: '20/07/2017', epoc: 1500505200 }

If anyone can give me some pointers i'd be very appreciative. The only thing that I've knowingly changed with it since it was last working is adding the if statement to catch if a date field hasn't been completed.

Sean T
  • 5
  • 4

1 Answers1

0

You need to use quotes to access the properties of an object.

var ys = dt['date']['year'];
moschn
  • 68
  • 5