You forgot to include button code. "The table keeps resetting" - what is table? Is field
kebab
your table? I'd expect to see recipes and ingredients (with counter) and a smart way to add/replace ingredient, with lookups, rather that funny way of changing array items at fixed index. Also note your checks are not guarding from invalid index exceptions properly.