Bird
0
0

Given this code snippet:

medium📝 Predict Output Q5 of 15
Angular - HTTP Client
Given this code snippet:
this.http.get('https://api.example.com/items').subscribe(items => console.log(items.length));

What will be logged if the server returns an array of 5 items?
Aundefined
B0
C5
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand response type

    The server returns an array of 5 items, so items is an array.
  2. Step 2: Access array length property

    items.length returns the number of elements, which is 5.
  3. Final Answer:

    5 -> Option C
  4. Quick Check:

    Array length property returns 5 [OK]
Quick Trick: Array responses have length property for count [OK]
Common Mistakes:
MISTAKES
  • Expecting undefined for array
  • Confusing length with index
  • Assuming error on array response

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes