I run this in node.js v11.6.0
const now = new Date(Date.now());
let date = now;
date.setFullYear(date.getFullYear() - 1);
let str = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate();
while(!data[str]){
date = date.setDate(date.getDate() - 1);
str = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate();
}
And get:
trail.js:15 str = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate();
TypeError: date.getFullYear is not a function
inside the while loop date.setDate() works but date.getFullYear() is not a function all of a sudden.