Is there a way to remove only one instance of an item from an array, even if there are multiple duplicates of that item? For example:
let array = ["abc", "def", "ghi", "def"];
const toRemove = "def";
I attempted to find the index and splice the array, but it ended up deleting the item completely.
const index = array.indexOf(toRemove);
console.log(array.splice(index,1)); //["def"]
Is there an alternative approach to achieve the desired result, where the remaining array is [ "abc", "ghi", "def" ]?