Javascript Equivalent Of PHP foreach


/ Published in: JavaScript
Save to your folder(s)

This is the equivalent of doing php's foreach loop in javascript.


Copy this code and paste it in your HTML
  1. //In PHP
  2.  
  3. foreach($data as $key => $value){
  4. //write code here
  5. }
  6.  
  7. //In Javascript the same construct looks like this
  8. for(key in obj){
  9. var value = obj[key];
  10. //write code here
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.