Setting the required attributes in a dynamic jquery table

I have two conditions that make required [id ^ = "Registration_numebr_multiply ["] ' and [id ^ = "vati_id_muultpliy ["] ' fields in a dynamic table using .each. These two functions work, but need to write a condition to them, if [id ^ = "Registration_numebr_multiply ["] 'is not empty then’ [id ^ = "vati_id_muultpliy ["] 'is required.

If it wasn’t for indexing ( [0], [1] ) it would be easier, maybe you have some idea

    jQ('[id^="Registration_numebr_multiply["]').each(function (index, item) {
        var thisId = jQ(this).attr('id');
        var index = thisId.substring(thisId.indexOf('[') + 1, thisId.indexOf(']'));
        jQ(`[id="Registration_numebr_multiply[${index}]`).attr("required", true);

    });
    };  

    jQ('[id^="vati_id_muultpliy["]').each(function (index, item) {
        var thisId = jQ(this).attr('id');
        var index = thisId.substring(thisId.indexOf('[') + 1, thisId.indexOf(']'));
        jQ(`[id="vati_id_muultpliy[${index}]`).attr("required", true);

    });