Increment key within multidimensional array in a form's input field using jQuery clone
<p>I'm trying to piece together info from these two answers, but neither seems to cover the issue in a way that I can extrapolate and get to work for my situation. So please don't punish me if this seems like a duplicate; I don't think it is.</p>

<p><a href="http://stackoverflow.com/questions/4466324/increment-multidimensional-array-when-form-fields-are-cloned">Increment multidimensional array when form fields are cloned</a></p>

<p><a href="http://stackoverflow.com/questions/5674764/copy-table-row-and-increment-all-name-attributes">Copy table row and increment all name attributes</a></p>

<pre><code>&lt;tr&gt;
    &lt;td&gt;&lt;input type="text" name="pricing['prices'][0]['label']" value="" /&gt;&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="pricing['prices'][0]['price']" value="" /&gt;&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="pricing['prices'][0]['expires']" value="" /&gt;&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="pricing['prices'][0]['bulk-price']" value="" /&gt;&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="pricing['prices'][0]['bulk-qty']" value="" /&gt;&lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p>is what I'm trying to clone, using this button:</p>

<pre><code>&lt;input type="button" id="newRowButton" value="Add Another Price" /&gt;
</code></pre>

<p>Script (so far the cloning works, but it doesn't change the "0" to a "1". I'm clearly missing something that I couldn't figure out by piecing together the examples in the other two answers)</p>

<pre><code>$("#newRowButton").live('click',function(e) {
    e.preventDefault();
  $("table.tablearray tr:last")
      .clone()
      .find(':input')
      .each(function(){
            this.name = this.name.replace(/\[(\d+)\]$/,
                                          function(str,p1){
                                              return '[' + (parseInt(p1,10)+1) + ']';
                                          });
        })
    .end()
    .appendTo("table")
});
</code></pre>

<p>Any help would be appreciated. Ideally I'd also like to add a "delete row" button too.</p>
