Skip to content

Multidimensional input : update index when clone existing item

Is it possible to change the index of the last item of a multidimensional input when my new item is created ?

Let me explain.

I have a button that is clone an item from my list, into my list. Each item contains several properties (date, category…)

This is an example of what I have when I display my form :


What I do is that I clone all my item, but for now, the index XXXX is not updated.

How can I update the XXXX directly when I clone my item ? I thought I could count the number of items, and then change the index, but this would be painful and time consuming…


Use a regex in match() to create array of them then update the one you want and join() back together

const el = document.querySelector('input');

const prefix ='[')[0],
      ind =[(.*?)]/g);

ind[5]= `[AAA]`; = `${prefix}${ind.join('')}`

<input name='validation_form[classe][0][matieres][11][ressources][XXXXX][hasBeenRenewed]'/>