Emulating the PHP foreach(){...} in javascript
7
Just a small snippet I discovered when I was tired writing somearrayname\[i\] I thought there was something like foreach in javascript but couldn't find any so why not make one?
For those foreach(){...} lovers.
Hope it makes your life easier.
For those foreach(){...} lovers.

Hope it makes your life easier.
d = ["a", "b", "c"]
for(var ind=0;(c = d[ind]);ind++){
alert(c);
}






for (i in objArray) {
var v=objArray[i];
}
I personally use the code below to do the same thing.
Array.prototype.each = function (f) {
for (var i=0;i<this.length;i++)
f(this[i],i);
}
d = ["a", "b", "c"]
d.each(function (item, index) {
alert(index + ": " + item);
});
var test = {x: 'a', y: 'b', z: 'c'};
for (value in test) {
alert(value);
alert(test[value]);
}