<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Queue and Stack methods for arrays </title>
<body>
<script>
The stack is a LIFO (LAST-IN-FIRST-OUT LIFO) data structure, and the behavior of the push () and pop ()-like stacks in JS
queue is a FIFO (first-in-first-out first-out) data structure, JS Shift () and unshift () similar to the behavior of the queue
push () and pop () change the original array, the push () method returns the length of the array, and the Pop () method returns the last item of the array
var colors = new Array ();
var count = Colors.push (' Red ', ' yellow ');
alert (count); 2
Count = Colors.push (' black ');
alert (count); 3
var item = Colors.pop ();
alert (item); " Black
alert (colors.length); 2
Colors.push (' Blue ', ' green ');
var first = Colors.shift ();
alert (first); Red
Colors.unshift (' white ');
alert (colors); White,yellow,blue,green
</script>
</body>
Queue and Stack methods for arrays