format
typescript
Stack.forEach(callback)class: Stack
description
Traverse the stack.
parameter
| param_name | type | description |
|---|---|---|
| callback | Callback | Callback function. |
reture
| type | description |
|---|---|
void |
code example
typescript
let stack = new Stack<Number>();
stack.Push(1);
stack.Push(2);
stack.Push(3);
let otherStack = new Stack<Number>();
let foreachCallback = (item: Number):void => {
otherStack.Push(item);
}
// Traverse the stack and push elements from stack to otherStack
stack.forEach(foreachCallback);