Console.log有没有办法命名发送变量? [英] Console.log is there a way to name sent variables?

查看:89
本文介绍了Console.log有没有办法命名发送变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将项目发送到console.log时有没有办法命名它们?类似于visual studio中的watch

When sending items to console.log is there a way to name them? Similar to "watch" in visual studio

例如我们有一个 var counter = 1;
所以在控制台日志中它显示为:

for example we have a var counter=1; so that in the console log it appears as:

counter 1
counter 2

依旧......

推荐答案

不是直接的,但你可以在输出时命名它们。

Not directly, but you can just name them when you output them.

console.log (和 .error .info .warn )让你同时传递任意数量的值,所以这样做是非常容易的:

console.log (and .error, .info, and .warn) let you pass any number of values at the same time, so it's super easy to just do something like this:

console.log('counter', counter);

输出如下:

counter 1

let counter = 0;

for (let i = 0; i < 5; i++) {
  counter++;
  console.log('counter', counter);
}

这篇关于Console.log有没有办法命名发送变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆