Whilst getting started with node.js I found myself needing lots of simple Javascript snippets equivalent to common PHP snippets.
Believe it or not, it took me too long for my liking to find the Javascript equivalent to PHP's foreach so I thought I'd put up another version.
In PHP, key/value iteration looks like this:
foreach ($myArray as $key => $value) {
// use $key and $value here
}
In Javascript, key/value iteration looks like this:
for (key in myArray) {
var value = myArray[key];
// use key and value here
}
Happy Javascripting :-)
792 comments,
Javascript, Saturday, September 11, 2010 17:58


