Search⌘ K
AI Features

Objects for Categorization

Explore how to use JavaScript objects to categorize and organize data by meal types. Learn to build a healthy meals tracker that calculates calorie and protein totals. Understand object creation, key-value pairs, and how to enhance your program with dynamic properties. This lesson helps you apply data structures for real-world nutrition tracking projects.

You’ve been tracking daily calories, but they’re just numbers in a single list. To make the data more useful, you can organize meals by type: for example, keep all breakfasts together, all lunches together, and all dinners together. Structuring the data makes calculating per-meal totals and seeing patterns over time easier.

Typing just:

Breakfast: 400
Lunch: 600
Dinner: 300

It's nice, but it doesn’t help you calculate totals for each category.

What you need is an object, a structure that stores data as key–value pairs so you can categorize and organize calories by meal type.

Your project: Build “Healthy Meals Object Tracker” that groups meals into categories (Breakfast, Lunch, Dinner), calculates totals for each, and shows the overall daily total.

The programming concept

Imagine you’re making a contacts app. If you only had an array, it might look like: ...