0

This is my spinet:

$scope.foodtypes = {
   'GRAINS': {
      'HOT': ['Rice','Beans','Sogum'],
      'ROOT': ['Yam','Potato','Cassava']
   }
}  

I like to store the exact word "GRAINS" or "ROOT" in a variable for decision making:

something like:

if foodtypes is "GRAINS" then ......

if foottypes is "ROOT" then ......

Please how do I capture "GRAIN" or "ROOT" for use?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
San
  • 1
  • 3

1 Answers1

-1

Assuming that foodtypes is a JSON string that represents an object that has all food types as first-level key, you could do something like this:

Object.keys(JSON.parse($scope.foodtypes));

This will return an array of strings ["GRAINS", "ROOT"].