如何隐藏console.log输出的对象内容

huangapple go评论60阅读模式
英文:

How hide output of console.log for object

问题

在Linux中,我在控制台日志中有如下关于对象的输出:

代码: console.log('PGN=======', pgn[z], '\n');

控制台: PGN======= ElementHandle {}

这是我需要的,只是提供对象存在的信息。

而在Windows中,对于同样的代码,我在控制台日志中得到以下输出:

控制台:

PGN======= ElementHandle {   _disposed: false,   _context:
ExecutionContext {
    _client: CDPSession {
      eventsMap: [Map],
      emitter: [Object],
      _callbacks: Map(0) {},
      _connection: [Connection]
      _targetType: 'page',..........
      和许多其他行 }

这是我不需要的。如何在Windows中禁止这种输出?

英文:

I have strange problem for me, for my little experience.

In linux i have this output in console.log for object:

code: console.log('PGN=======', pgn[z], '\n');

console: PGN======= ElementHandle {}

And this what me need, just info that the object exists.

In Windows i have this output in console.log for object (same code):

console:

 PGN======= ElementHandle {   _disposed: false,   _context:
 ExecutionContext {
     _client: CDPSession {
       eventsMap: [Map],
       emitter: [Object],
       _callbacks: Map(0) {},
       _connection: [Connection]
       _targetType: 'page',..........
         and many other lines }

And this what me not need. How this suppress in Windows?

答案1

得分: 1

你可以使用以下代码
console.log(pgn[z].constructor.name);

(适用于原始数据类型)。


<details>
<summary>英文:</summary>

You could go

console.log(pgn[z].constructor.name);

(works for primitives as well).


</details>



huangapple
  • 本文由 发表于 2023年5月31日 23:27:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76375113.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定