Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript stack

let stack = []
stack.push(2)      	// stack is now [ 2 ]
stack.push(5)      	// stack is now [ 2, 5 ]

let lastElement = stack[stack.length - 1]   // the las element is 5

let i = stack.pop() // stack is now [ 2 ]
console.log(i)      // displays 5


let queue = []
queue.push(2)    		// queue is now [ 2 ]
queue.push(5)        	// queue is now [ 2, 5 ]
let i = queue.shift()	// queue is now [ 5 ]
console.log(i)          // displays 2
 
PREVIOUS NEXT
Tagged: #javascript #stack
ADD COMMENT
Topic
Name
8+1 =