<!DOCTYPE HTML> <html> <head> <title>test1</title> </head> <body> <script> var arr={ "name":"zhansan", "age":23, "address":{ "city":"beijing", "gas":{ "gasSheet":"氣態流出物月報", "H_adjust":1 }, "time":{ "duration":31 } }, "units":{"title":"function"} } function show(obj){ var tmp={}; for(var i in obj){ if(obj[i]=="object"){ <span style="color:#ff0000;">tmp[i]=show(obj[i]);</span> } else{ <span style="color:#ff0000;">tmp[i]=obj[i]</span> } } return tmp; } var result=show(arr); console.log(result); </script> </body> </html>
</pre><p></p><p>利用遞歸思想,其中注意賦值語句</p><p>可用於不同的環境</p><p></p><pre>