Removing 'for each' from Javascript examples

In the recent Javascript examples posted here, I'd used for each (var item in items)… for iterating through objects and arrays. This is neat and convenient, but a) for each shouldn't be used with arrays and b) it doesn't work in WebKit/Safari and IE.

I've now updated the examples to use standard for loops, replacing

for each (var item in items)
with
for (var i = 0, item; item = items[i++];)

Aside: if you're reading a Planet that contains HubLog, those posts will all jump to the top - sorry! (I wish Planets dealt better with small updates so I didn't have to worry about it).

Comments

IIRC Venus at least does have an option to ignore changes to the atom:updated value. I guess it's up to the admins of the various Planet sites whether they want this behaviour or not.

Ah, I see you've had this conversation with Sam Ruby already :)

for (var item in items) will work, believe it or not.

Posted by: Navigateur on September 11, 2008 12:26 AM

Navigateur: true, but that only iterates through the keys, not the values.

All fields are optional, email address will not be shown; no HTML, URLs are automatically hyperlinked.