0

I am getting the number of apps installed on device, how can I filter them to only include the keys, google_maps and apple_maps ?

List of apps:

mapsAppInfo = {
baidu: false
cabify: false
citymapper: false
ee.mtakso.client: true
gaode: false
google_maps: true
here_maps: false
lyft: false
maps_me: false
moovit: false
sygic: false
taxis_99: false
uber: true
waze: false
yandex: false
}



  useEffect(() => {
    const loadAvailableMapApps = async () => {
      const mapsAppInfo = (await launcNavigator.getAvailableApps()) as AppInfo;
      
      const availableApps = Object.keys(mapsAppInfo).filter(
        (key) => mapsAppInfo[key],
      );

      setAvailableMapApps(availableApps);
    };

    // eslint-disable-next-line no-void
    void loadAvailableMapApps();
  }, []);
Bomber
  • 10,195
  • 24
  • 90
  • 167

1 Answers1

1

The easiest way would probably be to filter them by hand in your case. You can add another filter before the one you already have:

const availableApps = Object.keys(mapsAppInfo)
    .filter(k => (k === "google_maps" || k === "apple_maps")
    .filter(
        (key) => mapsAppInfo[key],
    );
Lorenz
  • 26
  • 1