You've managed to correct the issue where you were comparing the wrong thing:
this.restaurantList.filter((item) => {return item.city==givencity})
This is correct, you
should be looking at the
city
property. Now, if you're saying your console is printing
undefined
when you open your page then you need to take a look at your script:
let c = myobject.filterRestaurantByCity()
Your
filterRestaurantByCity
method has a parameter named
varansi
, but on this line you're not passing in a value. How do you expect the JS to filter by city if you're not providing a city name?