关于console的知识点

  1. table():用表格的形式显示数组或对象
    数组:

    const a=[1,2,444,66];
    console.table(a)


    对象:
    const a=[{a:'this a',b:'this b'},{a:'this a1',b:'this b1'}];
    console.table(a)

    只打印部分对象:
    const a=[{a:'this a',b:'this b',c:'this c'},{a:'this a1',b:'this b1',c:'this c1'}];
    console.table(a,['a','c'])
  2. time(timename)&timeEnd(timename):两者连用,开启一个计时器计算某操作执行时长。
    console.time("timer1");
    setTimeout(() => {
      console.timeEnd("timer1");
    }, 1000);


    上面那个setTimeout计时器执行时长为:1003.312255859375 ms
  3. count():记录打印同一内容的次数
    console.count('Hello');
    console.count('Hello word');
    console.count('Hello');
    console.count('Hello');
    console.count('Hello word');
    console.count('Hello');


    上面hello 打印了4次,hellow word 打印了2次
  4. assert():当不满足条件才打印
    const age = 18,height=30;
    console.assert(age > 17, "User is unable to drive");//true
    console.assert(age > 21, "User is below 21");//false
    console.assert(height>17,'height <17');//true
    console.assert(height>21,'height<21');//true

    const age = 18,height=15;
    console.assert(age > 17, "User is unable to drive");//true
    console.assert(age > 21, "User is below 21");//false
    console.assert(height>17,'height <17');//false
    console.assert(height>21,'height<21');//false

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值