SOURCE

class Stack{
    constructor() {
        this.items = []
    };
    push(ele){
        this.items.push(ele)
    }
    pop(){ //从栈顶删除
        return this.items.pop()
    }
    peek(){  //返回栈顶元素
        return this.items[this.items.length-1]
    }
    isEmpty(){
        return this.items.length === 0
    }
    clear(){
        this.items = []
    }
    size(){
        return this.items.length
    }
}

const stack = new Stack()

console.log(stack.isEmpty())

stack.push(3)
stack.push(5)
console.log(stack.peek())
console 命令行工具 X clear

                    
>
console