0
0
Javascriptprogramming~15 mins

Object entries in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Object entries
πŸ“– Scenario: You have a small online store. You keep a list of products and their prices in an object.You want to see each product with its price printed out clearly.
🎯 Goal: Build a program that uses Object.entries() to get product names and prices, then prints each product with its price.
πŸ“‹ What You'll Learn
Create an object called products with exact entries: 'apple': 1.2, 'banana': 0.5, 'orange': 0.8
Create a variable called entries that stores Object.entries(products)
Use a for loop with variables product and price to iterate over entries
Print each product and price in the format: Product: apple, Price: 1.2
πŸ’‘ Why This Matters
🌍 Real World
Objects are used to store related data like product lists, user info, or settings in many programs.
πŸ’Ό Career
Understanding how to work with objects and their entries is essential for web development and JavaScript programming jobs.
Progress0 / 4 steps
1
Create the products object
Create an object called products with these exact entries: 'apple': 1.2, 'banana': 0.5, 'orange': 0.8
Javascript
Need a hint?

Use curly braces {} to create an object and separate entries with commas.

2
Get entries from the products object
Create a variable called entries that stores Object.entries(products)
Javascript
Need a hint?

Use Object.entries() to get an array of key-value pairs from the object.

3
Loop over the entries
Use a for loop with variables product and price to iterate over entries
Javascript
Need a hint?

Use for (const [product, price] of entries) to get each product and price.

4
Print each product and price
Inside the loop, print each product and price in the format: Product: apple, Price: 1.2
Javascript
Need a hint?

Use console.log with a template string to print the product and price.