Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Ouputs the object's property and values to an string array
- Example:
- var theobj = {
- name: "Joe",
- phone: "(713) 987-3652"
- };
- var arr = outputObject(theobj);
- document.write(arr.join(""));
- */
- function outputObject(settings, ignoreFunctions, showobj) {
- var html = [];
- html.push("<ol>");
- for (key in settings) {
- var val = settings[key];
- var isfunc = typeof (val) === "function";
- var isobj = typeof (val) == "object";
- var typePart = " [" + typeof (val) + "]";
- if (ignoreFunctions && isfunc) continue;
- if (isobj) typePart = "";
- var clr = "green";
- if (val == null || val == undefined) clr = "red";
- else if (isobj) clr = "blue";
- html.push("<li style='color:" + clr + ";'>" + [key] + " = " + val + typePart);
- if (!showobj) continue;
- if (isobj) {
- var subref = val;
- html.push("<ul>");
- for (sub in subref) {
- var subval = subref[sub];
- var issubfunc = typeof (subval) === "function";
- if (ignoreFunctions && issubfunc) continue;
- var subtypePart = " [" + typeof (subval) + "]";
- html.push("<li style='color:#8600ff;'>" + [sub] + " = " + subval + subtypePart + "</li>");
- }
- html.push("</ul>");
- }
- html.push("</li>");
- }
- html.push("</ol>");
- return html;
- }
Advertisement
Add Comment
Please, Sign In to add comment