I have a string that includes some color tags, that looks like this:
[GREEN][BLUE][RED]
The position of the tags can be different. So [GREEN]
could be in middle or in the last position as well.
Now I have a new color tag that should be added to that list, let's call it [YELLOW]
. So [YELLOW]
has a dynamic position number, let's take the variable const position = 2
. Well, that means that [YELLOW]
should be placed in second place, which should look like this:
[GREEN][YELLOW][BLUE][RED]
How can I do this?