Complete the code to add an element to the top of the stack.
stack.push([1]);To add an element to the top of the stack, use push(element).
Complete the code to remove the top element from the stack.
const top = stack.[1]();To remove the top element from the stack, use pop().
Fix the error in the code to check if the stack is empty.
if (stack.[1] === 0) { console.log('Stack is empty'); }
The correct property to check the number of elements in an array is length.
Fill both blanks to peek at the top element without removing it.
const top = stack[stack.[1] [2] 1];
To peek the top element, access the last index which is length - 1.
Fill all three blanks to implement a function that checks if the stack is empty.
function isEmpty(stack) {
return stack.[1] === [2];
}
console.log(isEmpty([3]));The function returns true if stack.length === 0. The argument to test is stack.
