javascript - How to print out all the values inside object? -
i'm using function write values inside object.
<script type="text/javascript"> function print_r(theobj){ if(theobj.constructor == array || theobj.constructor == object){ document.write("<ul>") for(var p in theobj){ if(theobj[p].constructor == array || theobj[p].constructor == object){ document.write("<li>["+p+"] => "+typeof(theobj)+"</li>"); document.write("<ul>"); document.alert(p.typeof(theobj)); print_r(theobj[p]); document.write("</ul>") } else { document.write("<li>["+p+"] => "+theobj[p]+"</li>"); //alert(p+" "+theobj[p]); } } document.write("</ul>") } } </script>
it prints out values inside object
print_r({"total":4,"offset":0});
but how can tweaked print values if there object, this:
print_r({"total":4,"offset":0,"memberdata":{"firstname":"joe","lastname":"smith"}});
if need output object neatly on screen can do
function print_r(obj) { document.body.innerhtml = '<pre>' + json.stringify(obj, null, 4) + '</pre>'; }
Comments
Post a Comment