0
0
Javascriptprogramming~30 mins

Nested objects in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Nested objects
πŸ“– Scenario: You are managing a small library system. Each book has details like title, author, and availability status inside nested objects.
🎯 Goal: You will create a nested object to store book information, add a configuration for checking availability, extract titles of available books, and finally display those titles.
πŸ“‹ What You'll Learn
Create a nested object with exact book details
Add a variable to check if a book is available
Use a loop to collect titles of available books
Print the list of available book titles
πŸ’‘ Why This Matters
🌍 Real World
Nested objects are common when storing detailed information like user profiles, product catalogs, or library systems.
πŸ’Ό Career
Understanding nested objects and how to access them is essential for frontend and backend developers working with JSON data and APIs.
Progress0 / 4 steps
1
Create the nested object with book details
Create a constant object called library with two books: book1 and book2. Each book should be an object with these exact properties and values: title as a string, author as a string, and status as an object with a boolean property available. Use these exact values: book1: title "The Great Gatsby", author "F. Scott Fitzgerald", available true; book2: title "1984", author "George Orwell", available false.
Javascript
Need a hint?

Remember to nest the status object inside each book object.

2
Add a variable to check availability
Create a constant called isAvailable and set it to the available property of book1 inside the library object.
Javascript
Need a hint?

Access nested properties using dot notation like library.book1.status.available.

3
Collect titles of available books
Create an empty array called availableBooks. Use a for...in loop with variable bookKey to iterate over library. Inside the loop, check if library[bookKey].status.available is true. If yes, push library[bookKey].title into availableBooks.
Javascript
Need a hint?

Use for...in to loop over object keys and check nested properties inside the loop.

4
Display the available book titles
Write a console.log statement to print the availableBooks array.
Javascript
Need a hint?

Use console.log(availableBooks) to show the array in the console.