JavaScript的console命令使用實(shí)例
這篇文章主要介紹了javascript的console命令使用實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
1.分類輸出
console.log('文字信息'); console.info('提示信息'); console.warn('警告信息'); console.error('錯(cuò)誤信息');
2.分組輸出
console.group('1'); console.log("1-1"); console.log("1-2"); console.groupEnd(); console.group('2'); console.log("2-1"); console.log("2-2"); console.groupEnd();
生成折疊的分組
console.group('1'); console.log("1-1"); console.log("1-2"); console.groupEnd(); console.group('2'); console.log("2-1"); console.log("2-2"); console.groupEnd();
嵌套
console.group('1'); console.group("1-1"); console.group("1-1-1"); console.log('內(nèi)容'); console.groupEnd(); console.groupEnd(); console.group("1-2"); console.log('內(nèi)容'); console.log('內(nèi)容'); console.groupEnd(); console.groupEnd(); console.groupCollapsed('2'); console.group("2-1"); console.log('內(nèi)容'); console.groupEnd(); console.group("2-2"); console.groupEnd(); console.groupEnd();
3.表格輸出
console.table()將傳入的對(duì)象,或數(shù)組以表格形式輸出
var Obj = { Obj1: { a: "a1", b: "b1", c: "c1" }, Obj2: { a: "a2", b: "b2", c: "c2" }, Obj3: { a: "a3", b: "b3", c: "c3" } } console.table(Obj);
var Arr = [ ["a1","b1","c1"], ["a2","b2","c2"], ["a3","b3","c3"], ] console.table(Arr);
4.查看對(duì)象
顯示一個(gè)對(duì)象的所有屬性和方法Console.dir()和Console.log()相同
var ss = { name: 'AA', title: 'title1', } console.log("console.dir(ss)"); console.dir(ss); console.log("console.log(ss)"); console.log(ss);
5.查看節(jié)點(diǎn)
Console.dirxml()顯示一個(gè)對(duì)象的所有屬性和方法
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Flowchart</title> <meta charset="UTF-8"> </head> <body> <div id="sample"> <div style="width: 100%; display: flex; justify-content: space-between"> <div id="myPaletteDiv" style="width: 150px; margin-right: 2px; background-color: whitesmoke; border: solid 1px black"></div> <div id="myDiagramDiv" style="flex-grow: 1; height: 720px; border: solid 1px black"></div> </div> </div> </body> </html> <script> console.log("console.dirxml"); console.dirxml(document.getElementById("sample")); console.log("console.log"); console.log(document.getElementById("sample")); </script>
6.條件輸出
- 當(dāng)?shù)谝粋€(gè)參數(shù)或返回值為真時(shí),不輸出內(nèi)容
- 當(dāng)?shù)谝粋€(gè)參數(shù)或返回值為假時(shí),輸出后面的內(nèi)容并拋出異常
console.assert(true, "see"); console.assert((function() { return true;})(), "see"); console.assert(false, "not see"); console.assert((function() { return false;})(), "not see");
7.記次輸出
輸出內(nèi)容和被調(diào)用的次數(shù)
(function () { for(var i = 0; i < 5; i++){ console.count("運(yùn)行次數(shù):"); } })()
8.追蹤調(diào)用堆棧
function add(a, b) { console.trace("Add"); return a + b; } function add2(a, b) { return add1(a, b); } function add1(a, b) { return add(a, b); } var x = add2(1, 1);
9.計(jì)時(shí)
- Console.time()中的參數(shù)作為計(jì)時(shí)器的標(biāo)識(shí),具有唯一性
- Console.timeEnd()中的參數(shù)來(lái)結(jié)束此標(biāo)識(shí)的計(jì)時(shí)器,并以毫秒為單位返回運(yùn)行時(shí)間
- 最多同時(shí)運(yùn)行10000個(gè)計(jì)時(shí)器
console.time("Chrome中循環(huán)1000次的時(shí)間"); for(var i = 0; i < 1000; i++) { } console.timeEnd("Chrome中循環(huán)1000次的時(shí)間");
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- .NET?Core控制臺(tái)應(yīng)用ConsoleApp讀取appsettings.json配置文件
- vue-cli3在main.js中console.log()會(huì)報(bào)錯(cuò)的解決
- 如何使用JS console.log()技巧提高工作效率
- Node.js中console.log()輸出彩色字體的方法示例
- js中console在一行內(nèi)打印字符串和對(duì)象的方法
- js console.log打印對(duì)象時(shí)屬性缺失的解決方法
- JavaScript查看代碼運(yùn)行效率console.time()與console.timeEnd()用法
- js 中的console使用示例詳解
相關(guān)文章
BootStrap Table 后臺(tái)數(shù)據(jù)綁定、特殊列處理、排序功能
本節(jié)主要介紹Bootstrap的后臺(tái)數(shù)據(jù)綁定、特殊列處理及列的排序功能,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下吧2017-05-05Javascript實(shí)現(xiàn)漢字和拼音互轉(zhuǎn)的終極方案
網(wǎng)上關(guān)于JS實(shí)現(xiàn)漢字和拼音互轉(zhuǎn)的文章很多,但是比較雜亂,有的不支持多音字、不支持聲調(diào)或者字典文件太大,無(wú)法根據(jù)實(shí)際需要滿足需求。這篇文章給大家修正整理網(wǎng)上的幾種常見(jiàn)方法,文章結(jié)尾還附簡(jiǎn)單的JS拼音輸入法,本文對(duì)大家具有一定的參考借鑒價(jià)值,下面一起看看吧。2016-10-10javascript 實(shí)現(xiàn)文本使用省略號(hào)替代(超出固定高度的情況)
這篇文章主要介紹了javascript 實(shí)現(xiàn)文本使用省略號(hào)替代(超出固定高度的情況)的相關(guān)資料,需要的朋友可以參考下2017-02-02js實(shí)現(xiàn)身份證號(hào)碼驗(yàn)證的簡(jiǎn)單實(shí)例
本篇文章主要是對(duì)js實(shí)現(xiàn)身份證號(hào)碼驗(yàn)證的簡(jiǎn)單實(shí)例進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-02-02JavaScript 判斷對(duì)象中是否有某屬性的常用方法
判斷對(duì)象中是否有某屬性的常見(jiàn)方式總結(jié),不同的場(chǎng)景要使用不同的方式。這篇文章給大家介紹了JavaScript 判斷對(duì)象中是否有某屬性的常用方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2018-06-06javascript實(shí)現(xiàn)uploadify上傳格式以及個(gè)數(shù)限制
這篇文章主要介紹了javascript如何限制uploadify上傳格式以及個(gè)數(shù)的實(shí)現(xiàn)方法,感興趣的小伙伴們可以參考一下2015-11-11JavaScript實(shí)用工具庫(kù)lodash?使用
Lodash是一個(gè)JavaScript的實(shí)用工具庫(kù),提供了很多常用的函數(shù)和工具,可以幫助我們更方便地操作數(shù)據(jù)和處理邏輯,這篇文章主要介紹了lodash?使用,需要的朋友可以參考下2024-04-04