Stack

data-structures. Stack

High-performance, LIFO (Last-In-First-Out) Stack data structure. Encapsulates an internal private array (#items) to prevent index tampering and optimize V8 memory locality and fast push/pop operations.

Constructor

new Stack(iteropt)

Description:
  • Creates a new Stack instance.
Source:
Parameters:
Name Type Attributes Description
iter Iterable <optional>
An optional iterable object to initialize the stack with.

Members

length

Description:
  • Gets the number of items currently in the stack (Array length compatibility alias).
Source:
Gets the number of items currently in the stack (Array length compatibility alias).

size

Description:
  • Gets the number of items currently in the stack.
Source:
Gets the number of items currently in the stack.

Methods

(generator) Symbol.iterator() → {Iterator}

Description:
  • Iterates through stack items from top to bottom (LIFO order).
Source:
Returns:
Type
Iterator

clear() → {Stack}

Description:
  • Removes all items from the stack.
Source:
Returns:
The Stack instance for fluent method chaining.
Type
Stack

isEmpty() → {boolean}

Description:
  • Checks whether the stack is empty.
Source:
Returns:
True if the stack contains no items, false otherwise.
Type
boolean

peek() → {*|undefined}

Description:
  • Returns the item from the top of the stack without removing it.
Source:
Returns:
The top item, or undefined if the stack is empty.
Type
* | undefined

pop() → {*|undefined}

Description:
  • Removes and returns the item from the top of the stack.
Source:
Returns:
The top item, or undefined if the stack is empty.
Type
* | undefined

push(…items) → {Stack}

Description:
  • Pushes one or more items onto the top of the stack.
Source:
Parameters:
Name Type Attributes Description
items * <repeatable>
Elements to push onto the stack.
Returns:
The Stack instance for fluent method chaining.
Type
Stack

toArray() → {Array}

Description:
  • Returns a shallow copy of the stack items as an Array from bottom to top.
Source:
Returns:
Array of items from bottom to top.
Type
Array