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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。