0

I have an object that contains this JSON format data from a covid API http call.

  {
    "Country": "Gambia",
    "Confirmed": 3526,
    "Deaths": 108,
    "Recovered": 1992
  },
  {
    "Country": "Thailand",
    "Confirmed": 3506,
    "Deaths": 59,
    "Recovered": 3342
  },
  {
    "Country": "Somalia",
    "Confirmed": 3465,
    "Deaths": 98,
    "Recovered": 2877
  },
  {
    "Country": "Guadeloupe",
    "Confirmed": 3426,
    "Deaths": 26,
    "Recovered": 837
  },
  ...

What I want to achieve is remove all object whos country is not "Thailand" and "Gambia" (or something else), so it looks like this

  {
    "Country": "Gambia",
    "Confirmed": 3526,
    "Deaths": 108,
    "Recovered": 1992
  },
  {
    "Country": "Thailand",
    "Confirmed": 3506,
    "Deaths": 59,
    "Recovered": 3342
  }

.filter and .subscribe were some suggestions I found online but they don't work as the compiler throws this error

Property 'filter' does not exist on type 'Object'

The only way I can access what's inside is through a for loop but I'm also not quite sure how as I tried several variance of the below code

  for (var key in obj){
    if(key == "Country"){
      if(obj[key] != "USA" && obj[key] != "Thailand"){
        delete data[key];
      }
    }
  }

I apologize if its a simple question as I'm fairly new to this.

0 Answers0