Repeater issue/problm

We are trying to use this repeater:
https://www.jqueryscript.net/form/Form-Fields-Repeater.html

It seems there is problem if you look at the demo.
https://www.jqueryscript.net/demo/Form-Fields-Repeater/

Try on demo to add for example four groups.(press three times add button).

Then remove all four groups by pressing Delete button.

Then press add again to add a new group.

If you inspect the name element it is:

The problem is with test[4]name. Normally it should be test[0]name.

It seems that when you delete element does not delete the counting.

So if you play a little bit with delete/add buttons counting is wrong.

Javascript of this is :

    jQuery.fn.extend({
     createRepeater: function () {
         var addItem = function (items, key) {
        var itemContent = items;
        var group = itemContent.data("group");
        var item = itemContent;
        var input = item.find('input,select');
        input.each(function (index, el) {
            var attrName = $(el).data('name');
            var skipName = $(el).data('skip-name');
            if (skipName != true) {
                $(el).attr("name", group + "[" + key + "]" + attrName);
            } else {
                if (attrName != 'undefined') {
                    $(el).attr("name", attrName);
                }
            }
        })
        var itemClone = items;
        $("<div class='items'>" + itemClone.html() + "<div/>").appendTo(repeater);
    };
    /* find elements */
    var repeater = this;
    var items = repeater.find(".items");
    var key = 0;
    var addButton = repeater.find('.repeater-add-btn');
    var newItem = items;
    if (key == 0) {
        items.remove();
        addItem(newItem, key);
    }

    /* handle click and add items */
    addButton.on("click", function () {
        key++;
        addItem(newItem, key);
    });
}
 });

Have anyone ever used this repeater? or have a version of this that works correct?