What happens when you delete the first element of an array?
The first element is removed, and all other elements shift one position to the left to fill the gap.
Click to reveal answer
beginner
Which TypeScript method removes the first element from an array?
The shift() method removes the first element and returns it, shifting remaining elements left.
Click to reveal answer
intermediate
What is the time complexity of deleting the first element in a typical array?
It is O(n) because all elements after the first must be shifted one position left.
Click to reveal answer
beginner
Show the array state after deleting the first element from [10, 20, 30, 40].
After deletion, the array becomes [20, 30, 40]. The element 10 is removed and others shift left.
Click to reveal answer
intermediate
Why might deleting the first element of an array be less efficient than deleting the last?
Deleting the last element usually takes O(1) time, but deleting the first requires shifting all elements, making it O(n).
Click to reveal answer
Which method removes the first element of an array in TypeScript?
Ashift()
Bpop()
Cslice()
Dsplice()
✗ Incorrect
The shift() method removes the first element and shifts the rest left.
What is the time complexity of deleting the first element in an array?
AO(1)
BO(n^2)
CO(log n)
DO(n)
✗ Incorrect
Deleting the first element requires shifting all other elements, so it takes O(n) time.
After deleting the first element from [5, 15, 25], what is the new array?
A[15, 25]
B[5, 15]
C[25]
D[5, 25]
✗ Incorrect
The first element 5 is removed, leaving [15, 25].
Which operation is generally faster on arrays?
ADeleting the first element
BDeleting the last element
CDeleting the middle element
DAll have the same speed
✗ Incorrect
Deleting the last element is O(1), faster than deleting the first which is O(n).
What happens internally when you delete the first element of an array?
AElements shift right by one
BArray size increases
CElements shift left by one
DArray becomes empty
✗ Incorrect
All elements move one position left to fill the gap left by the removed first element.
Explain how deleting the first element of an array affects the array structure and performance.
Think about what happens to all other elements after the first is removed.
You got /4 concepts.
Describe the difference between deleting the first element and the last element of an array in terms of efficiency.
Consider how many elements need to move in each case.
You got /4 concepts.
Practice
(1/5)
1. What does deleting the first element of an array using array.shift() do to the array?
easy
A. Removes the last element of the array
B. Removes the first element and shifts all other elements left
C. Deletes the entire array
D. Adds a new element at the beginning
Solution
Step 1: Understand shift() method
The shift() method removes the first element of the array.
Step 2: Effect on array elements
After removal, all other elements move one position to the left to fill the gap.
Final Answer:
Removes the first element and shifts all other elements left -> Option B
Quick Check:
shift() removes first element [OK]
Hint: Remember: shift() removes from start, pop() removes from end [OK]
Common Mistakes:
Confusing shift() with pop()
Thinking shift() deletes entire array
Assuming shift() adds elements
2. Which of the following is the correct syntax to remove the first element from an array named nums in TypeScript?
easy
A. nums.shift()
B. nums.removeFirst()
C. nums.pop()
D. nums.delete(0)
Solution
Step 1: Identify the method to remove first element
The correct method to remove the first element in TypeScript arrays is shift().
Step 2: Check other options
pop() removes last element, removeFirst() and delete(0) are invalid methods.
Final Answer:
nums.shift() -> Option A
Quick Check:
Use shift() to remove first element [OK]
Hint: Use shift() to remove first element, pop() for last [OK]
Common Mistakes:
Using pop() instead of shift()
Using non-existent methods like removeFirst()
Trying to delete with delete(0) which is invalid
3. What will be the output of the following TypeScript code?
let arr = [10, 20, 30, 40];
arr.shift();
console.log(arr);
medium
A. [40]
B. [10, 20, 30, 40]
C. [30, 40]
D. [20, 30, 40]
Solution
Step 1: Initial array and shift operation
The array starts as [10, 20, 30, 40]. Calling shift() removes the first element 10.
Step 2: Resulting array after shift
After removal, the array becomes [20, 30, 40].
Final Answer:
[20, 30, 40] -> Option D
Quick Check:
shift() removes first element, rest remain [OK]
Hint: shift() removes first element, so array starts from second element [OK]
Common Mistakes:
Expecting original array unchanged
Thinking shift() removes last element
Confusing output with pop() effect
4. Consider this TypeScript code snippet:
let numbers = [5, 10, 15];
numbers.shift;
console.log(numbers);
What is the issue and how to fix it?
medium
A. Missing parentheses after shift; fix by using numbers.shift()
B. shift is not a valid method; use pop() instead
C. Array is empty; no fix needed
D. shift() removes last element; use unshift() instead
Solution
Step 1: Identify the method call mistake
The code uses numbers.shift without parentheses, so the method is not called.
Step 2: Correct method call syntax
Adding parentheses numbers.shift() calls the method and removes the first element.
Final Answer:
Missing parentheses after shift; fix by using numbers.shift() -> Option A
Quick Check:
Method calls need parentheses [OK]
Hint: Always add () to call methods like shift() [OK]
Common Mistakes:
Forgetting parentheses on method calls
Using pop() instead of shift() incorrectly
Misunderstanding shift() removes first element
5. You have an array let fruits = ['apple', 'banana', 'cherry', 'date'];. You want to remove the first two fruits efficiently. Which code snippet correctly does this?
hard
A. fruits.shift(2);
B. fruits.pop(); fruits.pop();
C. fruits.splice(0, 2);
D. fruits.delete(0); fruits.delete(1);
Solution
Step 1: Understand removing multiple elements
fruits.shift(2); fruits.shift(2); is incorrect: shift() takes no arguments (ignores 2) and removes only the first element.
Step 2: Using splice for efficient removal
splice(0, 2) removes two elements starting at index 0 in one operation.
Step 3: Check other options
pop() removes from end, delete() is invalid for arrays.
Final Answer:
fruits.splice(0, 2); -> Option C
Quick Check:
Use splice to remove multiple from start efficiently [OK]
Hint: Use splice(0, n) to remove n elements from start at once [OK]
Common Mistakes:
Using shift(2) which only removes one element
Using pop() which removes from end
Using invalid delete() method
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.