Bird
0
0

You receive this nested JSON:

hard📝 Application Q8 of 15
Rest API - Request and Response Format
You receive this nested JSON:
{"departments": {"sales": {"employees": 10}, "hr": {"employees": 5}}}

How would you extract the number of HR employees in JavaScript?
Adata['departments'].hr.employees
Bdata.departments['hr']['employees']
CAll of the above
Ddata.departments.hr.employees
Step-by-Step Solution
Solution:
  1. Step 1: Understand JSON object access

    JavaScript allows dot notation and bracket notation to access nested properties.
  2. Step 2: Check each option's validity

    All options correctly access the hr employees count using valid syntax.
  3. Final Answer:

    All of the above -> Option C
  4. Quick Check:

    Multiple valid ways to access nested JSON [OK]
Quick Trick: Use dot or bracket notation to access nested JSON properties [OK]
Common Mistakes:
MISTAKES
  • Mixing dot and bracket notation incorrectly
  • Using wrong property names
  • Forgetting quotes in bracket notation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes