JSFiddle - React, Tailwind, and code Playground

by Lindsey Suarez

HTML

<div id="container">
    <div class="form-group">
        <input name="MyAttributes[1].Key" />
        <input name="MyAttributes[1].Value" />
    </div>
    <div class="form-group">
        <input name="MyAttributes[2].Key" />
        <input name="MyAttributes[2].Value" />
    </div>
</div>

JavaScript

$("#container > .form-group").each(function(i, el) {
    $("input", el).attr("name", function(j, name) {
        return name.replace(/\[\d*\]/, "[" + i + "]");
    });
});