Método Node.js console.groupEnd()

la consola El método groupEnd() es una interfaz de programación de aplicaciones incorporada del módulo de la consola que se utiliza para finalizar el grupo iniciado llamando al método console.group() o console.groupCollapsed(). Indica el final de un grupo de mensajes.

Sintaxis:

console.groupEnd();

Parámetros: Este método no acepta ningún parámetro.

Valor de retorno: este método no devuelve nada, pero finaliza el grupo en la consola.

Los siguientes ejemplos ilustran el uso de la consola. método groupEnd() en Node.js.

Ejemplo 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();

Ejecute el archivo index.js usando el siguiente comando:

node index.js

Salida de la consola:

GeeksforGeeks

  1st print from the first Collapsed group
  2nd print from the first Collapsed group

GeeksforGeeks after the Ending of the group

Ejemplo 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("===================================");

Salida de la consola:

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

===================================

Referencia: https://nodejs.org/api/console.html#console_console_groupend

Publicación traducida automáticamente

Artículo escrito por aditya32123 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *