How to Get Yesterday Date in JavaScript

Yesterday date in javascript- The setDate() method sets the day of the Date object relative to the beginning of the currently set month.If the dayValue is outside of the range of date values for the month, setDate() will update the Date object accordingly.

Use this code to Get yesterday date in javascript-

let today = new Date();
let yesterday = new Date();
yesterday.setDate(today.getDate() - 1);
console.log('Today: ' + today);
console.log('Yesterday: ' + yesterday);