Finally, we are going to implement the clear method. The clear method simply empties the stack, removing all its elements. The simplest way of implementing this method is as follows:
clear() { this.items = [];}
An alternative implementation would be calling the pop method until the stack is empty.
And we are done! Our Stack class is implemented.