Skip to content

format

typescript
Stack.Peek()

class: Stack

description

Get the element at the top of the stack without removing it.

parameter

param_nametypedescription

reture

typedescription
T|undefinedThe element at the top of the stack.

code example

typescript
let stack = new Stack<Number>();
stack.Push(1);
stack.Push(2);
stack.Push(3);
// Get the element at the top of the stack without removing it
let topItem = stack.Peek();
Debug.Log("Top element of the stack: ", topItem);