Module 4~9 min
Objects and Collections
Beyond simple lists, programs often need to represent more structured data. Objects let you group related information together by name.
What You'll Learn
- What an object is
- How objects differ from arrays
- A simple example of an object
Structured Data
An object groups related pieces of data together, each labeled with a name (called a key), rather than a numeric position. This makes it easy to represent something like a single real-world item with multiple properties.
Objects vs. Arrays
While an array is best for an ordered list of similar items, an object is better for describing a single thing with multiple named properties.
Example
A `user` object might have properties like `name: "Sam"` and `age: 25` -- each accessed by name rather than by numeric position.
Key Concepts
ObjectKeyProperty
Key Takeaways
- An object groups related data together using named keys
- Objects are well-suited to describing a single thing with multiple properties
- Arrays and objects serve different, complementary purposes
Knowledge Check
How are values typically accessed in an object?