Nous souhaitons ici boucler sur l'objet suivant :
var hash = {"key1": "value1", "key2": "value2"};
hash["key3"] = "value3";
Pour ce faire, il existe deux solutions.
La première :
Object.keys(hash).forEach(function (key) {
var value = hash[key]
console.log(key + " => " + value);
})
La seconde :
for (var key in hash) {
console.log(key + " => " + hash[key]);
}