Just noticed that there should be a colon instead of a comma between "dogs" and the array above. Assume it's due to transcription.
–
wombletonFeb 18 '09 at 0:08

51

Very important to check for dictionary.hasOwnProperty(key) otherwise you may end up with methods from the prototype chain..
–
TigraineJun 9 '11 at 6:16

3

From the same article: Iterates over the enumerable properties of an object, in arbitrary order. If key order is important, you need to do something like pushing them in an array, sorting it, and then using a for() loop to get keys from the sorted array with which to index the original object.
–
mcmlxxxviJul 26 '13 at 21:31

Just a quick note, be wary of using for..in if you use a library (jQuery, prototype, etc.), as most of them add methods to created Objects (including dictionaries).

This will mean that when you loop over them, method names will appear as keys. If you are using a library, look at the documentation and look for an enumerable section, where you will find the right methods for iteration of your objects.

this requires jQuery (which is fine) but you forgot to mention it :-)
–
Simon_WeaverMar 25 at 17:04

Floribon this isn't a joke. I use this in my JS all the time. The point is to show how to loop through the keyval pair DictionaryObj. If you have a better way or advice than please post, other than that, don't be a d**k.
–
ExzileMar 26 at 0:40

@Exzile sorry you got ofended. The question is about Javascript, a scripting langage used today in various environments including servers. You probably understand that an answer relying on jQuery, a heavy front-end DOM-manipulation library is not very relevant for such a question. I can see you revenged by adding the same comment on one of my question, that's not very serious..
–
floribonMar 26 at 10:14

I was trying to help and contribute, bashing doesn't help. Hoping to show you that.
–
ExzileMar 26 at 13:57