小編給大家分享一下JavaScript中如何將對(duì)象在轉(zhuǎn)化成string在控制臺(tái)中輸出,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

直接使用如下方法,在使用時(shí),直接consloe.log(objectString(object))
function objectString(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();
}看完了這篇文章,相信你對(duì)JavaScript中如何將對(duì)象在轉(zhuǎn)化成string在控制臺(tái)中輸出有了一定的了解,想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站制作公司行業(yè)資訊頻道,感謝各位的閱讀!
網(wǎng)頁(yè)題目:JavaScript中如何將對(duì)象在轉(zhuǎn)化成string在控制臺(tái)中輸出-創(chuàng)新互聯(lián)
路徑分享:http://chinadenli.net/article32/ccijpc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營(yíng)銷推廣、電子商務(wù)、網(wǎng)站維護(hù)、App開發(fā)、微信公眾號(hào)、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容