当前位置:网站首页>你不会只会用console.log()吧?
你不会只会用console.log()吧?
2022-06-12 12:08:00 【老电影故事】
console
1、我们一般只知道有console.log()这种用法
好吧,那我带您看看关于console的其它用法,请听我娓娓道来
2、console格式化打印
首先console.log()是我们都知道的。在里面我们一般都用于输出数据,其实在里面也可以设置输出的格式
console.log('hello i am a %s string','student')

console.log('%c I LOVE YOU','font-size:55px;color:pink')

呦,还可以加样式呢,是不算很屌
3、console.warn(),输出黄色的警告
console.warn('hello girl')

4、console.error(),输出红色的报错
console.error('hello error')

5、console.info,与console.log的效果没啥区别
console.info('hello world i am hero')

6、console.assert (),接收两个参数
第一个是关于boolen的值是什么,如果为true则第二个参数执行
console.assert(1===2,'this is wrong')

7、console.clear(),清空控制台

8、console.dir(),用于将设置的对象,dump化获得详细信息
9、console.group()和console.groupEnder(),将同一对象类型做一个分类
const dogs=[{
name:'jack',age:13},{
name:'lucy',age:12}]
dogs.forEach(dog=>{
console.group(`${
dog.name}`)
console.log(`this is ${
dog.name}`)
console.log(`${
dog.name} is ${
dog.age} year ago`)
console.log(`${
dog.name} is ${
dog.age*4} year ago`)
console.groupEnd(`${
dog.name}`)
})

10、console.count(),对输出相同数据的数据进行排序
console.count('wes')
console.count('good')
console.count('wes')
console.count('wes')
console.count('good')
console.count('good')
console.count('wes')
console.count('good')

11、console.time(),统计一段代码运行的时间
console.time('fetching data');
fetch('https://api.github.com/users/wesbos')
.then(data => data.json())
.then(data => {
console.timeEnd('fetching data');
console.log(data);
})

12、console.table( ),用于对输出的数据以表格的形式进行展示
const dogs=[{
name:'jack',age:13},{
name:'lucy',age:12}] console.table(dogs)

是不算学到啦,666
边栏推荐
- Analyze the implementation principle of the onion model, and connect the onion model in your own project
- win7注册进程外组件, 服务, 以及COM组件调试
- 机器学习基础概念
- Cookie和Session
- Promise controls the number of concurrent requests
- 什么是模块化?模块化的好处
- 服务端渲染与客户端渲染的区别(优缺点)
- 【QNX Hypervisor 2.2 用户手册】4 构建QNX Hypervisor系统
- Neighbor item status update of neighbor subsystem
- 【QNX Hypervisor 2.2 用户手册】4.1 构建QNX Hypervisor系统的方法
猜你喜欢

First understand the onion model, analyze the implementation process of middleware, and analyze the source code of KOA Middleware

开源项目-(ERP+酒店+电商)后台管理系统

LeetCode 497. 非重叠矩形中的随机点(前缀和+二分)

TinyMCE series (II) TinyMCE plug-in development
![[foundation of deep learning] learning of neural network (4)](/img/8d/0e1b5d449afa583a52857b9ec7af40.png)
[foundation of deep learning] learning of neural network (4)

TinyMCE realizes automatic uploading of pasted pictures

Common debugging tools and commands for ROS

QML first day
![[foundation of deep learning] back propagation method (1)](/img/0b/540c1f94712a381cae4d30ed624778.png)
[foundation of deep learning] back propagation method (1)

【Leetcode】79. Word search
随机推荐
for in 与Object.keys()的区别
【QNX Hypervisor 2.2 用户手册】4 构建QNX Hypervisor系统
如何确定首页和搜索之间的关系呢?首页与搜索的关系
Advantages and disadvantages of single page development and multi page development
关于报文
【深度学习基础】神经网络的学习(4)
What is modularity? Benefits of modularity
Dom+js+ carousel map + no time
Compiling Draco library on Windows platform
Basic concepts of machine learning
Miscellaneous instructions of arm instruction set
Spark common encapsulation classes
【Leetcode】199. Right view of binary tree
JS to load and display Excel files
About message
Neighbor item status update of neighbor subsystem
Reasons for SSL introduction and encryption steps
Common debugging tools and commands for ROS
[译] QUIC Wire Layout Specification - Packet Types and Formats | QUIC协议标准中文翻译(2) 包类型和格式
传统的DOM渲染方式?