var obj = { key: value1, key: value2}
I would like to iterate it and get pars of (key and value1) and (key and value2)
if I use simple cycle:
for (var i in obj){
console.log(obj[i])
}
I got:
key value2
key value2
so obj[i] always take last key
Keys in JS objects must be unique.
What happens, is:
sets
obj['key']tovalue1.The subsequent declaration of
key : value2overwrites your previous one.Possible solution to your problem:
Another, possibly more elegant, solution would be to modify the way you store your data like so:
This obviously allows for multiple entries with the same key. The querying could be done somewhere along these lines: