I can think of 2 possibilities, which one do you want?
For example, this is already in the array:
[0, 'Form1']
[1, 'Form2']
[2, 'Form3']
[4, 'Form4']
User does not close Form4 but clicks the Form2. Which result do you want?
Result1:
[0, 'Form1']
[1, 'Form2']
[2, 'Form3']
[4, 'Form4']
[5, 'Form2']
Result2:
[0, 'Form1']
[1, 'Form3']
[2, 'Form4']
[3, 'Form2']
I saw you're not using dynamic array, so my guess you want Result2. I am not saying Result1 is better, each one has its own advantages, disadvantages and its use case. Is it correct, Result2 is what you want? Or maybe something else?