1 g5 r3 l! l" y; B: r5 b+ Q; k. l 5. console.time()和console.timeEnd()/ a6 D0 L" |/ ? M; N, p. F
无论何时我们想知道一段代码或一个函数所需要花费的时间,都可以使用JavaScript控制台对象提供的time()和timeEnd()方法。关键是要有一个必须相同的标签,而里面的代码可以是任何东西(函数、对象、甚至直接console.log()都可以)。! J( G; _6 y! ^4 J: r2 E
// console.time() and console.timeEnd() method
// console.time() method
console.time("Let's see time console")
let time1 = function(){
console.log('time1 function is running')
}
let time2 = function(){
console.log('time2 function is running')
}
time1()
time2()
// console.timeEnd() method
console.timeEnd('Time Taken')
, l% h' N6 N% c$ ~5 l 6. console.table() ! _+ T$ |5 B+ Y; |# w" B这个方法允许我们在控制台中生成表格。输入数据必须是数组或显示为表格的对象。2 o# G2 L k& Y& C8 t4 F
// console.group() and console.groupEnd() method
// console.group() method
console.group('This is a sample group')
console.log('This is a sample group log')
console.warn('This is a sample group warning')
console.error('This is a sample group error')
// console.groupEnd() method
console.groupEnd('This is a sample group')
console.log('This is a new section')