Published
- 1 min read
javascript stack last element
The solution for this is noted below
javascript stack last element
Solution
let stack = []
stack.push(1)
stack.push(2)
stack.push(3)
stack.push(4)
let i = stack.pop()
let lastElement = stack[stack.length - 1]
console.log(i, lastElement) // i = 4, lastElement = 3
Try other methods by searching on the site. That is if this doesn’t work