DEV Community

Arunkumar Subramani
Arunkumar Subramani

Posted on

To achieve stack in simple way in JavaScript

Stack:

Inserting element into last of your array, remove element top of your array(LIFO).



let stack = [];
//insert element
stack.push(1);
stack.push(2);
stack.push(3);
//output [1,2,3]
//remove element
stack.pop()
//output [1,2]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)