Nodejs: How to loop through an associative array

Problem

So let's say I have an array with a bunch of values say

"abc" = 5
"bcd" = 12
"ddd" = 13

I would like to be able to loop through and print all these out in a format similar to

abc: 5
bcd: 12
ddd: 13

If there is an assoc. array that's quite large and I don't know all the keys. How do I print out all of the keys and values?

Thanks

Problem courtesy of: adsfdsafdsa

Solution

Try this:

for(var prop in obj) {
    if(obj.hasOwnProperty(prop)){
        console.log(prop + ': ' + obj[prop]);
    }
}
Solution courtesy of: Havsmonstret

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.