JS debugging often hit the output of the content is the object and can not print, alert can only print out the object, but can not print out the contents, it is inconvenient, so the various aspects of the summary of the following a function, can be an array or objects such as the results of one by one print out, The specific code is as follows:
function Writeobj (obj) {
var description = "";
for (var i in obj) {
var property=obj[i];
description+=i+ "=" +property+ "\ n";
}
alert (description);
}
Also when you need to convert object objects to string strings .
The following function is good, you can convert it to a string type, and then you can print it, the specific code is as follows:
function Obj2string (o) {
var r=[];
if (typeof o== "string") {return
"\" +o.replace (/([\ \ \ \ \])/g, "\\$1"). replace (/\ n)/g, "\\n"). Replace (/\ R)/g, " \ \ \ r "). Replace (/\ t)/g," \\t ") +" \ ";
}
if (typeof o== "Object") {
if (!o.sort) {for
(var i in O) {
R.push (i+ ":" +obj2string (O[i));
}
if (!! Document.all&&!/^\n?function\s*tostring\ (\) \s*\{\n?\s*\[native code\]\n?\s*\}\n?\s*$/.test (o.toString)) {
R.push ("toString:" +o.tostring.tostring ());
}
R= "{" +r.join () + "}";
} else{for
(var i=0;i<o.length;i++) {
R.push (obj2string (o[i))
}
r= "[" +r.join () + "]";
}
return r;
}
return o.tostring ();
More about the content of JS printing function, click on "JS Printing function Summary" topic Learning
The above two steps will be able to complete the JS print object, I hope to help you learn.