Javascript - 模板字符串不会将对象漂亮地打印出来。

10 浏览
0 Comments

Javascript - 模板字符串不会将对象漂亮地打印出来。

我可以使用ES6模板字符串来美观地打印JavaScript对象吗?这是来自一个React Native项目的内容,console.log()输出到Chrome调试工具中。

我想要的结果

const description = 'App opened';
const properties = { key1: 'val1', blah: 123 };
console.log('Description: ', description, '. Properties: ', properties);

输出

Pretty printing

尝试使用模板字符串

// 相同的description和properties
const logString = `Description: ${description}. Properties: ${properties}`;
console.log(logString);

输出

enter image description here

问题

如何使用模板字符串获得第一个输出(美观打印)的结果?

0