console.groupCollapsed()方法是控製台模塊的內置模塊,用於折疊分組的內容,直到調用console.groupEnd()方法為止。它開始折疊組,並可以使用groupEnd()方法結束。
用法:
console.groupCollapsed([label]);
參數:如上所述,此方法僅接受一個參數,如下所述:
標簽:您要在控製台上分組的組的標簽。這是一個可選參數。
返回值:它不返回任何值。
以下示例說明了Node.js中console.groupCollapsed()方法的使用。
範例1:
index.js
// Node.js program to demonstrate the
// console.groupCollapsed() method
// This code example demonstrate the
// method without parameter
// Accessing console module
const console = require('console');
console.log("GeeksforGeeks (Outside)")
console.log();
// Creating first group calling
// console.groupCollapsed() method
console.groupCollapsed();
// Printing First line of Group
console.log("GeeksforGeeks (1)");
// Printing Second line of Group
console.log("GeeksforGeeks (2)");
// End the group (It is used to end the
// group for more understanding the
// group method)
console.groupEnd();
console.log();
使用以下命令運行index.js文件:
node app1.js
輸出:
GeeksforGeeks (Outside) GeeksforGeeks (1) GeeksforGeeks (2)
範例2:
index.js
// Node.js program to demonstrate the
// console.groupCollapsed() method
// This code example demonstrate the method
// with parameter and nested groups
// Accessing console module
const console = require('console');
console.log("GeeksforGeeks ");
console.log("=========================");
console.log();
// Creating collapsed group
console.groupCollapsed("GeeksforGeeks (main Collapsed group)");
console.log();
// Printing First line of collapsed group
console.log("GeeksforGeeks (Outside)");
console.log();
// Creating First nested collapsed group
console.groupCollapsed("GeeksforGeeks (1st Nested group)");
console.log("GeeksforGeeks (1st line)");
console.log("Computer Science Portal (2nd line)");
// Ending the 1st nested gtoup
console.groupEnd();
console.log();
console.log();
// Creating second nested collapsed group
console.groupCollapsed("GeeksforGeeks (2nd Nested group)");
console.log("Data Structure (1st line)");
console.log("Algorithms & segment tree (2nd line)");
// Ending the 2nd nested group
console.groupEnd();
console.log();
// Printing last line of Main group
console.log("Main group finished");
console.log();
// Calling groupEnd() method (It is used
// to end the group for more understanding
// the group method)
console.groupEnd();
// print from outside the Main group
console.log("GeeksforGeeks (Outside Last)");
console.log();
console.log("=========================");
輸出:
GeeksforGeeks ========================= GeeksforGeeks (main Collapsed group) GeeksforGeeks (Outside) GeeksforGeeks (1st Nested group) GeeksforGeeks (1st line) Computer Science Portal (2nd line) GeeksforGeeks (2nd Nested group) Data Structure (1st line) Algorithms & segment tree (2nd line) Main group finished GeeksforGeeks (Outside Last) =========================
參考: https://nodejs.org/api/console.html#console_console_groupcollapsed
相關用法
- Node.js console.timeLog()用法及代碼示例
- Node.js fs.fsyncSync()用法及代碼示例
- Node.js process.nextTick()用法及代碼示例
- Node.js x509.toLegacyObject()用法及代碼示例
- Node.js GM charcoal()用法及代碼示例
- Node.js GM blur()用法及代碼示例
- Node.js GM sharpen()用法及代碼示例
- Node.js GM drawLine()用法及代碼示例
- Node.js GM drawArc()用法及代碼示例
- Node.js GM drawPolyline()用法及代碼示例
- Node.js GM drawBezier()用法及代碼示例
注:本文由純淨天空篩選整理自aditya32123大神的英文原創作品 Node.js console.groupCollapsed() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。