I have an array that contains some single items and some arrays:
var groceries = ["toothpaste", ["plums", "peaches", "pineapples"], ["carrots", "corn", "green beans"], "orange juice", ["chocolate", "ice cream"], "paper towels", "fish"];
I want to write a function to remove some of these items or arrays when called.
For the single items, I wrote this function:
function removeItems(arr, item) {
for ( var i = 0; i < item.length; i++ ) {
var index = arr.indexOf(item[i]);
if (index > -1) {
arr.splice(index, 1);
}
}
};
So then I can call:
removeItems(groceries, ["fish", "orange juice"]);
And this works exactly as I want it to. However, I can't figure out how to make the function also be able to remove the arrays (e.g. ["chocolate", "ice cream"]) from within the larger array. How would I go about that?