ใช้เมธอด HTML DOM console.groupEnd() เพื่อระบุจุดสิ้นสุดของกลุ่มข้อความ ออกจากกลุ่มข้อความปัจจุบันในคอนโซล
ไวยากรณ์
Follwing เป็นไวยากรณ์สำหรับเมธอด console.groupEnd() -
console.groupEnd()
ตัวอย่าง
ให้เราดูตัวอย่างสำหรับ HTML DOM console.groupEnd() วิธีการ -
<!DOCTYPE html>
<html>
<body>
<h1>console.groupEnd() Method</h1>
<p>Press F12 key to view the message in the console view.</p>
<button type="button" onclick="groupMessage()">GROUP</button>
<button type="button" onclick="EndGroup()">END GROUP</button>
<script>
function groupMessage(){
console.group();
console.log("This message will be inside a group!");
console.log("This message will also be inside a group!");
}
function EndGroup(){
console.groupEnd();
console.log("We are now outside the group");
console.log("This message will be outside the group!");
}
</script>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

เมื่อคลิกปุ่ม GROUP และดูมุมมองคอนโซลในตัวเลือกสำหรับนักพัฒนา -

เมื่อคลิกปุ่ม END GROUP และดูมุมมองคอนโซลในตัวเลือกสำหรับนักพัฒนา -

ในตัวอย่างข้างต้น −
เราได้สร้างปุ่มสองปุ่ม GROUP และ END GROUP ที่จะรันเมธอด groupMessage() และ EndGroup () เมื่อผู้ใช้คลิก -
<button type="button" onclick="groupMessage()">GROUP</button> <button type="button" onclick="EndGroup()">END GROUP</button>
เมธอด groupMessage() มีเมธอด console.group() อยู่ข้างใน โดยระบุข้อความทั้งหมดที่เขียนหลังจากจุดนี้จะแสดงในกลุ่มข้อความ -
function groupMessage(){
console.group();
console.log("This message will be inside a group!");
console.log("This message will also be inside a group!");
} เมธอด EndGroup() มีเมธอด console.groupEnd() อยู่ข้างใน ซึ่งระบุข้อความทั้งหมดที่เขียนหลังจากจุดนี้ จะแสดงนอกกลุ่มข้อความ จะไม่เกิดข้อผิดพลาดหากไม่มีกลุ่มข้อความก่อนหน้า -
function EndGroup(){
console.groupEnd();
console.log("We are now outside the group");
console.log("This message will be outside the group!");
}