I solved the problem using your comments:
1) There was no single quote:
<script th:inline="javascript"> /*<![CDATA[*/ var xxx = '${states}'; console.log(xxx); /*]]>*/ </script>
2) The object should be analyzed as follows:
var hashmap = $.parseJSON(xxx);
3) And before I need to serialize my object (this is not an ajax call, so I need to serialize it manually):
Map<String, List<String>> states... model.addAttribute("states", new ObjectMapper().writeValueAsString(states));
So now I can read my object:
var myList = hashmap['STATE1']; console.log(myList )
will print [a, b, c, d] and I can execute the loop:
for(i in myList ){ console.log(myList[i]); }
source share