title: Get the last 30 days from an Array with Dates
body: <p>What I am trying to achieve is to get all entries from an array in a range of the last 30 days and push this into a new array which I can work with afterwards.</p>
  <p>My array (this.trades) looks like this:</p>
  <pre><code>{
  id: &quot;95&quot;,
  datum: &quot;2020-03-11&quot;,
  trade: &quot;EUR/USD BUY&quot;,
  aktion: &quot;closed&quot;,
  pips: &quot;10&quot;
  },
  {
  id: &quot;94&quot;,
  datum: &quot;2020-06-09&quot;,
  trade: &quot;GBP/USD BUY&quot;,
  aktion: &quot;TP Hit&quot;,
  pips: &quot;65&quot;
  },
  {
  id: &quot;93&quot;,
  datum: &quot;2020-06-08&quot;,
  trade: &quot;NZD/USD SELL&quot;,
  aktion: &quot;SL Hit&quot;,
  pips: &quot;-57&quot;
  },
  </code></pre>
  <p>datum is the german word for date.
  the array is pretty long (filled with 95 entries over the past half year).</p>
  <p>So my desired output would be:</p>
  <ul>
  <li>to sort the Array by its date (this.trades.datum)</li>
  <li>to extract all the entries within the last 30 days</li>
  <li>and finally push this into a new array to work with (containing all the other keys)</li>
  </ul>
  <p>I'm working in a vuejs project and have the opportunity to use computed properties for calculating, i'm also using momentjs library.</p>
  <p>Here is my current function, where i convert datum into dateobjects:
  But i want to get only the entries from the last 30 days.</p>
  <pre><code> chartDatumMonth() {
        let data = this.trades;
        data.forEach(d =&gt; {
          d.dateObj = moment(d.datum);
        });
        console.log(data);
        return data;
      },
  </code></pre>
  <p>console output:</p>
  <pre><code>(80) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, __ob__: Observer]
  0:
  aktion: (...)
  dateObj: Moment
  _d: Wed Aug 05 2020 00:00:00 GMT+0200 (Mitteleuropäische Sommerzeit) {}
  _f: &quot;YYYY-MM-DD&quot;
  _i: &quot;2020-08-05&quot;
  _isAMomentObject: true
  _isUTC: false
  _isValid: true
  _locale: Locale {_calendar: {…}, _longDateFormat: {…}, _invalidDate: &quot;Invalid date&quot;, _dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/, ordinal: ƒ, …}
  _pf: {empty: false, unusedTokens: Array(0), unusedInput: Array(0), overflow: -1, charsLeftOver: 0, …}
  __proto__: Object
  datum: &quot;2020-08-05&quot;
  id: (...)
  pips: (...)
  trade: (...)
  __ob__: Observer {value: {…}, dep: Dep, vmCount: 0}
  get aktion: ƒ reactiveGetter()
  set aktion: ƒ reactiveSetter(newVal)
  get datum: ƒ reactiveGetter()
  set datum: ƒ reactiveSetter(newVal)
  get id: ƒ reactiveGetter()
  set id: ƒ reactiveSetter(newVal)
  get pips: ƒ reactiveGetter()
  set pips: ƒ reactiveSetter(newVal)
  get trade: ƒ reactiveGetter()
  set trade: ƒ reactiveSetter(newVal)
  __proto__: Object
  1:
  aktion: (...)
  dateObj: Moment {_isAMomentObject: true, _i: &quot;2020-08-04&quot;, _f: &quot;YYYY-MM-DD&quot;, _isUTC: false, _pf: {…}, …}
  datum: &quot;2020-08-04&quot;
  </code></pre>