How do i pretty print javascript objects/variables?
This question already has an answer here:
Change the above example to:
var user = {
first: 'Jack',
last: 'Green',
age: 54
};
// plain console log
console.log(JSON.stringify(user, undefined, 2));
// or with interpolation:
console.log(`User: ${JSON.stringify(user, undefined, 2)}`);
and now we get the nice looking output:
{
"first": "Jack",
"last": "Green",
"age": 54
}
User: {
"first": "Jack",
"last": "Green",
"age": 54
}
链接地址: http://www.djcxy.com/p/8452.html
上一篇: 重复字符串