I'm pretty new to javascript and I'm trying to iterate over a dictionaries key/values. (And yes, I read a few posts here, but didn't find the answere for.)
So this is my dictionary:
showhidedict = {
0: ["a"],
1: [],
2: ["a", "b"],
3: []
};
this is my iterating:
for (var value in showhidedict)
$("#" + showhidedict[value]).hide();
resharper suggests me to add the hasOwnProperty
-check into the loop:
if (showhidedict.hasOwnProperty(value))
But why?
the hasOwnProperty
-check checks, whether an object has an attribute (here, whether the dictionary contains the key), right?
But do I really need the check? Since I iterate over the keys, I know all keys must exist. Are there other points why I should add the check?