// console.warn() method
console.warn('This is a sample Warning')
0 k* }3 h9 \6 R2 n2 y* F' o) V. B4. console.clear()' v# Y; |3 R8 ?, Q8 \( U
用于清除控制台信息。清除控制台时,如果是基于Chromium的浏览器,将打印一个简单的叠加文本,如下面的截图所示“Console was cleared”,而在Firefox中,则不会返回任何消息。 0 t3 q0 E8 H# F. F& V
// 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')
( O' h. ^3 n* s7 H7 n% T) y8 o- E 6. console.table() # P6 J, G7 c( I) a! K1 j这个方法允许我们在控制台中生成表格。输入数据必须是数组或显示为表格的对象。 / E+ h! T7 a: `5 j
// console.count() method
console.log('This is a sample count')
for(let i=0; i<10; i++){
console.count('This is iteration number', i)
}
) X) j/ k0 e4 u2 x 8. console.group()和console.groupEnd()9 p7 w2 v, |" t K3 ^, N
控制台对象的group()和groupEnd()方法允许我们将内容分组到单独的代码块中,并且这些代码块将缩进。和time()和timeEnd()一样,它们也接受值相同的标签。 : m3 |, A g4 C. x4 |: X% N
// 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')