Emulating the PHP foreach(){...} in javascript





7
Date Submitted Sat. Mar. 3rd, 2007 5:55 AM
Revision 1 of 1
Scripter shachi
Tags foreach | JavaScript
Comments 4 comments
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.

d = ["a", "b", "c"]

for(var ind=0;(c = d[ind]);ind++){
alert(c);
}
 

Shachi Bista

Comments

Comments PHP forEach
Thu. Mar. 8th, 2007 1:53 PM    Scripter Fordiman
Comments Extending the core...
Tue. Mar. 6th, 2007 7:03 PM    Helper albud
  Comments No there isn't
Wed. Nov. 28th, 2007 7:51 AM    Helper HRCerqueira
  Comments Nice!!
Thu. Mar. 8th, 2007 11:10 AM    Scripter shachi

Voting