Basic JavaScript Question:
Download Questions PDF

How to make a array as a stack using JavaScript?

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 Interview Questions And Answers PDF

Previous QuestionNext Question
How to use "join()" to create a string from an array using JavaScript? How to shift and unshift using JavaScript?