Strange Javascript Problem Involving split("/");
<p>Okay, so using the following function:</p>

<pre><code>function date_add(date, days)
{
  var dim = {1:31, 2:28, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31};
  console.log(date.split("/"));
  var date_arr = date.split("/");
  console.log(date_arr);
  ...
}
</code></pre>

<p>I get the following output at the console screen for date_add("12/08/1990", 1)</p>

<pre><code>["12", "08", "1990"]
["2", "08", "1990"]
</code></pre>

<p>Spending an hour struggling with what could fix this weird problem, on a whim I changed my function to the following:</p>

<pre><code>function date_add(date, days)
{
  var dim = {1:31, 2:28, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31};
  date = date.split("/");
  console.log(date);
  ...
}
</code></pre>

<p>Magically, the code works again.  Now don't get me wrong, I'm ecstatic that it worked.  I'm seriously concerned over <em>why</em> it worked, though, when the other didn't.  More or less I'm just concerned with why the other didn't work.  Does anyone have a good explanation?</p>

<p><strong>Edit</strong>: Now they're both broken. >.></p>

<p>For Tomas, here is the full function:</p>

<pre><code>function date_add(date, days)
{
  var dim = {1:31, 2:28, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31};
  console.log(date);
  console.log(date.split("/"));
  date_arr = date.split("/");
  console.log(date)
  if (date_arr[0][0] = "0") date_arr[0] = date_arr[0][1];
  if (date_arr[1][0] = "0") date_arr[1] = date_arr[1][1];
  var month = parseInt(date_arr[0]);
  var day   = parseInt(date_arr[1]);
  var year  = parseInt(date_arr[2]);
  console.log(month);
  console.log(day);
  console.log(year);

  if ((year%4 == 0 &amp;&amp; year%100 != 0) || year%400 == 0)
    dim[2] = 29;

  day += days;
  while (day &lt; 1)
  {
    month--;
    if (month &lt; 1)
    {
      month = 12;
      year--;
    }
    day += dim[month];
  }

  while (dim[month] &lt; day)
  {
    day -= (dim[month]+1);
    month++;
    if (month &gt; 12)
    {
      month = 0;
      year++;
    }
  }

  return ""+month+"/"+day+"/"+year;
}
</code></pre>

<p>As for the input for the function, I called this function from the console using <code>date_add('12/08/1990',1);</code></p>
