0
0
Javascriptprogramming~15 mins

Object keys and values in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Object keys and values
πŸ“– Scenario: You work in a small shop and keep track of products and their prices in an object. You want to see all the product names and their prices separately.
🎯 Goal: Learn how to get all keys and values from an object using JavaScript.
πŸ“‹ What You'll Learn
Create an object called products with exact keys and values
Create a variable called productNames to hold the keys of products
Create a variable called productPrices to hold the values of products
Print both productNames and productPrices to see the lists
πŸ’‘ Why This Matters
🌍 Real World
Objects are used to store related data like product lists, user profiles, or settings in many web applications.
πŸ’Ό Career
Knowing how to access keys and values in objects is essential for frontend and backend developers working with data structures.
Progress0 / 4 steps
1
Create the products object
Create an object called products with these exact entries: "apple": 2, "banana": 1, "orange": 3.
Javascript
Need a hint?

Use curly braces {} to create an object with keys and values.

2
Get the product names
Create a variable called productNames and set it to the keys of the products object using Object.keys(products).
Javascript
Need a hint?

Use Object.keys() to get all keys from an object.

3
Get the product prices
Create a variable called productPrices and set it to the values of the products object using Object.values(products).
Javascript
Need a hint?

Use Object.values() to get all values from an object.

4
Print the product names and prices
Write two console.log statements to print productNames and productPrices.
Javascript
Need a hint?

Use console.log(variableName) to print the variables.