简体   繁体   中英

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. 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":

在此处输入图片说明

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:

 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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