Basic JavaScript Question:
Download Job Interview Questions and Answers 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
<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 Question | Next Question |
How to use "join()" to create a string from an array using JavaScript? | How to shift and unshift using JavaScript? |