Iterating over the properties of an object


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

JSLint requires the body of every `for in` statement should be wrapped in an `if` statement


Copy this code and paste it in your HTML
  1. var buz = {
  2. fog: 'stack'
  3. };
  4.  
  5. for (var name in buz) {
  6. if (buz.hasOwnProperty(name)) {
  7. alert("this is fog (" + name + ") for sure. Value: " + buz[name]);
  8. }
  9. else {
  10. alert(name); // toString or something else
  11. }
  12. }

URL: http://www.jslint.com/lint.html#for%20in

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.