Home  >  Article  >  Web Front-end  >  JavaScript imitates PHP's print_r function to output json data_javascript skills

JavaScript imitates PHP's print_r function to output json data_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:22:411169browse
复制代码 代码如下:

//theOb(json数据)
function print_r(theObj) {
var retStr = '';
if (typeof theObj == 'object') {
retStr = '
';
for (var p in theObj) {
if (typeof theObj[p] == 'object') {
retStr = '
[' p '] => ' typeof(theObj) '
';
retStr = '
' print_r(theObj[p]) '
';
} else {
retStr = '
[' p '] => ' theObj[p] '
';
}
}
retStr = '
';
}
return retStr;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn