I am returning HashMap<Long,String> from server on one of the Ajax calls. How can I iterate over the it to extract key,value pair?
Thank you
Return it as JSON object:
{1:"String",5:"Foo"}
On the client, you can then access the elements then using data[1] and data[5]. While it looks like an array access, JavaScript will do the right thing (Kudos to Felix Kling for pointing that out).
var obj = {5: 'foo'};. It's true that the property has to be accessed with obj[5], but that's not "array access", it's called bracket notation and is just an alternative way to access properties. See the MDN documentation. In fact, arrays are just objects themselves and each element of the array is a property (with a numeric property name) of that underlying object.
JSON?