title: Getting the last X days date with Moment.js
body: <p>I want to get the last <code>x</code> dates from the current date using <code>Moment.js</code>.</p>
  
  <pre><code>const moment = require('moment');
  
  let dates;
  const dates = [];
  const NUM_OF_DAYS = 12; // get last 12 dates.
  
  for (let i = 0; i &lt; NUM_OF_DAYS; i++) {
    date = moment();
    date.subtract(1, 'day').format('DD-MM-YYYY');
    dates.push(date);
  }
  
  console.log(dates);
  </code></pre>
  
  <p>The result of this code is as follows:</p>
  
  <pre><code>[ moment("2018-07-09T11:40:04.663"),
    moment("2018-07-09T11:40:04.675"),
    moment("2018-07-09T11:40:04.675"),
    moment("2018-07-09T11:40:04.675"),
    moment("2018-07-09T11:40:04.675"),
    moment("2018-07-09T11:40:04.675"),
    moment("2018-07-09T11:40:04.675"),
    moment("2018-07-09T11:40:04.675"),
    moment("2018-07-09T11:40:04.675"),
    moment("2018-07-09T11:40:04.675"),
    moment("2018-07-09T11:40:04.675"),
    moment("2018-07-09T11:40:04.675") ]
  </code></pre>
  
  <p>This is the same date and not the previous of what I want for each iteration.</p>
  
  <p>I know the issue is with the line <code>date = moment()</code> because it is returning the current timestamp and not the previous at each step.</p>
  
  <p>How can I fix this?</p>