I've searched a bunch of Javascript tutorials but there are too many simple ones making it hard to find a detailed one that answers my question. I have an array that looks like this:
var food = [
['apple', 'strawberry', 'orange'],
['carrots', 'beans', 'peas'],
['cookies', 'cake', 'muffins', 'pie']
];
I want to be able to loop through each of these items by category looking for a specific value. Something like this would be nice:
for (var i in food.fruit) {
if(food.fruit[i] == "apple") {
console.log("Found "+food.fruit[i]);
}
}
But I don't know how to setup the array so I can reference it by category. The following just throws an error about the colon.
var food = [
fruit: ['apple', 'strawberry', 'orange'],
veggies: ['carrots', 'beans', 'peas'],
sweets: ['cookies', 'cake', 'muffins', 'pie']
];
I'm asking because later I'll want even more complex categories like food.fruit.color or something and need it all in one array so I can easily reference the values I need. Thanks.