Convert phoenix form name to id with javascript?

If I have the form field name how do I get the corresponding id?

for example

item[a][b][c]item_a_b_c

does it work in all possible scenarios to just remove ]$, replace ][ with _ and [ with _

name.replace(/]$/, "").replaceAll("][", "_").replaceAll("[", "_")

Why don’t you put form IDs in your Phoenix templates?

because I am generating new form fields, so I need to generate a new name and a corresponding new id

Probably this will help Phoenix.HTML.Form — Phoenix.HTML v3.2.0