I'm trying to get the other item out of an array. I have an array called fruit and a variable called apples. I want to go through the array and find any other fruit apart from the one I already have.
Thanks in advance for any help
var fruit = [
"apples",
"pears"
];
var alreadyHave = "apples";
for( var i = 0; i < fruit.length; i++){
if (! fruit[i] === alreadyHave) {
fruit.splice(i, 1);
}
}
console.log(fruit);
I would like to set the remaining fruit as another variable.