1.console.log()方法在打印原始类型变量的时候会正常的输出,如string,number...,在输出对象类型的时候就会得到
[object Array]或[object Object],这时候就需要使用JSON.stringify()进行数据格式转换;
2.扩展jquery方法实现打印不同类型的数据
$.extend({
log:function(message){
if(typeof(message) == "object"){
console.log(JSON.stringify(message,undefined,4));
}else{
console.log(message);
}
}
})
输入:var arr = [{name:'xxx',age:'11'},{name:'yyy',age:'12'}]
var arr1 = ['xx','yy']
$.log(arr);
$.log(arr1);
控制台打印结果:[
{
"name": "xxx",
"age": "11"
},
{
"name": "yyy",
"age": "12"
}
]
[
"xx",
"yy"
]
扩展jquery 实现增强版console.log方法
最新推荐文章于 2023-05-10 11:19:16 发布