Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 17:22:41
Original
1238 people have browsed it
复制代码 代码如下:

//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;
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template