控製台。 groupEnd()方法是控製台模塊的內置應用程序編程接口,用於通過調用方法console.group()或console.groupCollapsed()來結束已啟動的組。它指示消息組的結尾。
用法:
console.groupEnd();
參數:此方法不接受任何參數。
返回值:此方法不會返回任何內容,但會在控製台上結束該組。
以下示例說明了控製台的使用。 Node.js中的groupEnd()方法。
範例1:
index.js
// Node.js program to demonstrate the
// console.groupEnd() method
// This code example demonstrate the method
// with console.groupCollapsed() method
// Accessing console module
const console = require('console');
console.log("GeeksforGeeks");
console.log();
console.groupCollapsed();
// Printing First line of Group
console.log("1st print from the first Collapsed group");
// Printing Second line of Group
console.log("2nd print from the first Collapsed group");
// Calling the groupEnd() method
console.groupEnd();
console.log();
// Printing out of the group
console.log("GeeksforGeeks after the Ending of the group");
console.log();
使用以下命令運行index.js文件:
node index.js
控製台輸出:
GeeksforGeeks 1st print from the first Collapsed group 2nd print from the first Collapsed group GeeksforGeeks after the Ending of the group
範例2:
index.js
// Node.js program to demonstrate the
// console.group() method
// This code example demonstrate the
// method with console.group() method
// Accessing console module
const console = require('console');
console.log("GeeksforGeeks ");
console.log("================================");
console.log();
// Creating main group
console.group("This is the starting main group");
console.log();
// Printing First line of group
console.log("1st group and not from any nested group");
console.log();
// Creating first nested group inside main group
console.group("Starting of the 1st Nested group");
// Printing 1st line
console.log("Hello Geeks for Geeks from "
+ "1st Main Nested group");
// Printing 2nd line
console.log("Computer Science Portal(Geeks for "
+ "Geeks) from 1st Main Nested group");
// Ending of the first nested group
// Calling the groupEnd() method
console.groupEnd();
console.log();
console.log();
// Creating second nested group
console.group("Starting of the 2nd Main Nested group");
// Printing 1st line
console.log("Hello from 2nd Main Nested group");
// Printing 2nd line
console.log("Hello from 2nd Main Nested group");
// Ending of the first nested group
// calling the groupEnd() method
console.groupEnd();
console.log();
// Printing last line of the group
console.log("Now Main group will end");
console.log();
// Calling groupEnd() method (It is used to
// end the group for more understanding
// the group method)
// Calling the groupEnd() method
console.groupEnd();
// Printing from outside the Main group
console.log("This the Hello from GeeksforGeeks"
+ " from outside the Main Group");
console.log();
console.log("===================================");
控製台輸出:
GeeksforGeeks ================================ This is the starting main group 1st group and not from any nested group Starting of the 1st Nested group Hello Geeks for Geeks from 1st Main Nested group Computer Science Portal(Geeks for Geeks) from 1st Main Nested group Starting of the 2nd Main Nested group Hello from 2nd Main Nested group Hello from 2nd Main Nested group Now Main group will end This the Hello from GeeksforGeeks from outside the Main Group ===================================
參考: https://nodejs.org/api/console.html#console_console_groupend
相關用法
- 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.groupEnd() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。