Nodejs: How to loop through an associative array


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?


Problem courtesy of: adsfdsafdsa


Try this:

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


There is currently no discussion for this recipe.

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