Is there a way to insert a key value pair at a specific index in an array? I am currently struggling with this task.
Here is the code I have been working on:
this.quiz.push(
{
"question-no":this.no,
"Ans":this.ans
}
I require this functionality to store the user's selected choice for each question in the array. If the user decides to change their selection, I want to replace it within the same position in the array. However, it seems that a new element is being created instead of replacing the existing one. I am unsure how to go about inserting the key value pair at a particular index. Can someone provide assistance?
Thank you in advance.