in the line this.data[this.top]
is this.data is the array and then this.top is what?
Stack using arrays
this.top is actually telling the position(index) of an element inside the stack. If the stack if empty then we assign
this.top = -1, and when an element is to be entered in the stack(this process is called push in stack), then we increment top by 1 i.e. (this.top)++(which make top=0). then we do this.data[this.top]=valueToBePushed.
so clearly this first value inside the stack has index 0.
as you learnt stack works as LIFO. so the last element is at top of the stack and the index of this last element is this.top.
for eg. say array size is 100, but total elements till now are only 10(stack size is 10). so this.top will be 9(which is index of last element entered).
Thanks