jQuery: Generate "name" Attribute Array Dynamically
<p>I have a form like this:</p>

<pre><code>&lt;form&gt;
  &lt;div class="repeatable"&gt;
    &lt;div class="repeatable"&gt;
      &lt;div class="repeatable"&gt;
        &lt;input name="level_three"&gt;
        &lt;input name="inner_three"&gt;
        &lt;a&gt;+&lt;/a&gt;
      &lt;/div&gt;
      &lt;input name="level_two"&gt;
      &lt;a&gt;+&lt;/a&gt;
    &lt;/div&gt;
    &lt;input name="level_one"&gt;
    &lt;a&gt;+&lt;/a&gt;
  &lt;/div&gt;
&lt;/form&gt;
</code></pre>

<p>The plus sign clones the entire <code>repeatable</code> closest to itself. I want a jQuery function to iterates through <code>repeatable</code>s and make the input name's an array like this:</p>

<pre><code>&lt;form&gt;
  &lt;div class="repeatable"&gt;
    &lt;div class="repeatable"&gt;
      &lt;div class="repeatable"&gt;
        &lt;input name="level_three[0][0]"&gt;
        &lt;input name="inner_three[0][0]"&gt;
        &lt;a&gt;+&lt;/a&gt;
      &lt;/div&gt;
      &lt;div class="repeatable"&gt;
        &lt;input name="level_three[0][1]"&gt;
        &lt;input name="inner_three[0][1]"&gt;
        &lt;a&gt;+&lt;/a&gt;
      &lt;/div&gt;
      &lt;input name="level_two[0]"&gt;
      &lt;a&gt;+&lt;/a&gt;
    &lt;/div&gt;
    &lt;div class="repeatable"&gt;
      &lt;div class="repeatable"&gt;
        &lt;input name="level_three[1][0]"&gt;
        &lt;input name="inner_three[1][0]"&gt;
        &lt;a&gt;+&lt;/a&gt;
      &lt;/div&gt;
      &lt;div class="repeatable"&gt;
        &lt;input name="level_three[1][1]"&gt;
        &lt;input name="inner_three[1][1]"&gt;
        &lt;a&gt;+&lt;/a&gt;
      &lt;/div&gt;
      &lt;div class="repeatable"&gt;
        &lt;input name="level_three[1][2]"&gt;
        &lt;input name="inner_three[1][2]"&gt;
        &lt;a&gt;+&lt;/a&gt;
      &lt;/div&gt;
      &lt;input name="level_two[1]"&gt;
      &lt;a&gt;+&lt;/a&gt;
    &lt;/div&gt;
    &lt;input name="level_one"&gt;
    &lt;a&gt;+&lt;/a&gt;
  &lt;/div&gt;
&lt;/form&gt;
</code></pre>

<p>We may have any number of <code>repeatable</code>s. In the example there are 3 levels total. It may 1, 2, 3, 4 or any number.</p>