Bird
0
0

Why does this code throw an error?

medium📝 Debug Q7 of 15
Angular - Reactive Forms
Why does this code throw an error?
const fa = new FormArray([]);
fa.removeAt(5);
AIndex 5 does not exist in the FormArray
BremoveAt() requires a FormControl argument
CFormArray cannot be empty
DremoveAt() is not a method of FormArray
Step-by-Step Solution
Solution:
  1. Step 1: Check FormArray length

    The array is empty, so index 5 is out of bounds.
  2. Step 2: Understand removeAt behavior

    Calling removeAt(5) on an empty array causes an error because that index does not exist.
  3. Final Answer:

    Index 5 does not exist in the FormArray -> Option A
  4. Quick Check:

    removeAt index must exist [OK]
Quick Trick: removeAt index must be valid [OK]
Common Mistakes:
MISTAKES
  • Thinking removeAt needs a control argument
  • Assuming empty FormArray is invalid
  • Confusing removeAt with clear()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes