title: How to convert a date with "nd","rd", "th" into a yyyy-mm-dd format Javasciript
body: <p>I have an array of dates like:</p>
  
  <pre><code>dates=['2nd Oct 2014','20th Oct 2014','20th May 2019']
  </code></pre>
  
  <p>and I want to return them as an array in the YYYY-MM-DD format. 
  so far I have this:</p>
  
  <pre><code>function formatDate(dates) {
  var t=[];
  dates.map(function(date){
   var d = new Date(date),
          month = '' + (d.getMonth() + 1),
          day = '' + d.getDate(),
          year = d.getFullYear();
  
      if (month.length &lt; 2) month = '0' + month;
      if (day.length &lt; 2) day = '0' + day;
      t.push([year, month, day].join('-'));
  });
  console.log(t);
  
  
      return t;
  }
  var dates = ['2nd Oct 2014','20th Oct 2014','20th May 2019']
   console.log(formatDate(dates));
  </code></pre>
  
  <p>but this gives me :</p>
  
  <pre><code>[NaN-NaN-NaN,NaN-NaN-NaN,NaN-NaN-NaN]
  </code></pre>
  
  <p>since its not able to recognize the date with "th", "nd".any idea how to fix this so that I get the o/p as:</p>
  
  <pre><code>[2014-10-02,2014-10-20,2019-05-20]
  </code></pre>
  
  <p>here is the fiddle: <a href="http://jsfiddle.net/nakpchvf/" rel="nofollow noreferrer">http://jsfiddle.net/nakpchvf/</a></p>
  
  <p>Thanks!</p>