Seeking guidance on a small project of mine.
For example, I have these two arrays:
chosenItems = ['apple', 'banana', 'cherry', 'date', 'kiwi']
availableFruits = ['apple', 'cherry', 'grape', 'kiwi']
My goal is to compare the chosenItems
array with the availableFruits
array. If an item in chosenItems
is not present in availableFruits
, then it should be removed from chosenItems
.
Outcome:
chosenItems = ['apple' 'cherry', 'kiwi']
availableFruits = ['apple', 'cherry', 'grape', 'kiwi']
I am aware that I can achieve this task using for-loops, but I am interested in exploring if there is a more efficient way to accomplish this using JavaScript.