Basic JavaScript Question:

How to make a array as a stack using JavaScript?

Tweet Share WhatsApp

Answer:

The pop() and push() functions turn a harmless array into a stack in JavaScript...

<script type="text/javascript">
var numbers = ["one", "two", "three", "four"];
numbers.push("five");
numbers.push("six");
document.write(numbers.pop());
document.write(numbers.pop());
document.write(numbers.pop());
</script>

This produces
sixfivefour

Download JavaScript PDF Read All 114 JavaScript Questions
Previous QuestionNext Question
How to use "join()" to create a string from an array using JavaScript? How to shift and unshift using JavaScript?