Posted By

Abe on 03/21/08


Tagged

object properties


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

SpinZ
Juntalis


Get Object Properties


 / Published in: JavaScript
 

URL: http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256BF8004D72D6

  1. function dumpProps(obj, parent) {
  2. // Go through all the properties of the passed-in object
  3. for (var i in obj) {
  4. // if a parent (2nd parameter) was passed in, then use that to
  5. // build the message. Message includes i (the object's property name)
  6. // then the object's property value on a new line
  7. if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
  8. // Display the message. If the user clicks "OK", then continue. If they
  9. // click "CANCEL" then quit this level of recursion
  10. if (!confirm(msg)) { return; }
  11. // If this property (i) is an object, then recursively process the object
  12. if (typeof obj[i] == "object") {
  13. if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
  14. }
  15. }
  16. }

Report this snippet  

You need to login to post a comment.