this might be an odd question, but I have a map Long-String pair:
10 ANIMAL
11 BACTERIA
12 SHROOM
I send this HashMap from Spring Controller to View:
Map<Long, String> catMap = filterService.generateCatMap();
...
mv.addObject("catMap", catMap);
In the view I can print the key value pair easily by iterating or directly by catMap[‘KEY’]
Problem is that I have a JS function where I have to pass the KEY and I know the VALUE. So this is reverse from map: get value by key.
Is it possible actually to get the key by knowing the value without iterating? (I have to mention that keys and values are unique, no duplicates)
See if the above code logic helps. It can help you to retreive both the key and value in the loop. You can use a script function inside the forEach loop and do your required operation as desired.