Thought I would share this in case people needed it as I couldn't find something similar.
I am wondering if it is possible to remove an item from an array even if duplicates of that item exist.
Lets look at some code:
var myArray = ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'd', 'd', 'e'],
itemToRemove = 'a',
itemToAdd = 'f';
For the example above, I want to remove itemToRemove
from the array, BUT, I do not want to remove all of them, just 1. I then want to add itemToAdd
.
To give a little context, I am build a category/personality based quiz, each answer to a question has a category. I want to store all chosen categories in an array, then display a result dependent on which category is most common at the end of the quiz.
Where the question comes in is the User can go back and change their choice if they want, so if they do change their mind, I need to remove the previous category and add the new one.