I have an array that may contain multiple elements:
"coachID" : [
"choice1",
"choice2"
]
If the user selects choice2, I want to rearrange the array like this:
"coachID" : [
"choice2",
"choice1"
]
Similarly, if there are more than 2 elements in the array;
"coachID" : [
"choice1",
"choice2",
"choice3"
]
and the user chooses choice2, the array should be rearranged as follows:
"coachID" : [
"choice2",
"choice1",
"choice3"
]
Essentially, the selected element should always be positioned at the beginning of the array.
How can I implement this functionality using TypeScript?