Call Us : +91-8376986802 (Viber, WhatsApp)

How to make a array as a stack using JavaScript?



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

var numbers = [“one”, “two”, “three”, “four”];
numbers.push(“five”);
numbers.push(“six”);
document.write(numbers.pop());
document.write(numbers.pop());
document.write(numbers.pop());

This produces
sixfivefour

Leave a Reply