Looping Through Javascript Object


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



Copy this code and paste it in your HTML
  1. //two level object literal
  2. var valid = {
  3. fName : {
  4. req : true,
  5. max : 6
  6. },
  7. lName : {
  8. req : true,
  9. max : 10
  10. }
  11. }
  12.  
  13.  
  14. var fld;
  15.  
  16. //fld is text value of object key
  17. for(fld in valid)
  18. {
  19.  
  20. console.log(valid[fld].req);
  21. }
  22.  
  23.  
  24. //Will display
  25. true
  26. true
  27. 23

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.