简体   繁体   English

在 Metro console.log 中突出显示对象属性

[英]highlighting object property in metro console.log

I have to console.log a big object in metro and I would like to highlight an specific property.我必须在地铁中 console.log 一个大对象,我想突出显示一个特定的属性。 For example:例如:

let bigObject = {a:1,b:2,c:3,d:4};
console.log(bigObject)

And when I console.log the whole thing, I would like to highlight property "c":当我 console.log 整个事情时,我想突出显示属性“c”:

在此处输入图片说明

Is there a way to do this ?有没有办法做到这一点 ?

  • This should work, however, you will need to print them separately:这应该有效,但是,您需要单独打印它们:

 let bigObject = { a: 1, b: 2, c: 3, d: 4 }; console.log(bigObject.a); console.log(bigObject.b); console.log('%c' + bigObject.c, 'background: blue; color: white'); console.log(bigObject.d);

It seems that the snippet doesn´t support the console style.该代码段似乎不支持控制台样式。

  • Using a forEach() loop:使用forEach()循环:

 let bigObject = { a: 1, b: 2, c: 3, d: 4 }; Object.keys(bigObject).forEach(e => { if (e === 'c') console.log('%c' + e + ": " + bigObject[e], 'background: blue; color: white'); else console.log(e + ": " + bigObject[e]); });

More info at: https://developer.mozilla.org/en-US/docs/Web/API/console#usage更多信息请访问: https : //developer.mozilla.org/en-US/docs/Web/API/console#usage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM