Lesson 5: Arrays of Objects
In this lesson, you'll see how to combine arrays and objects in JavaScript. An object can hold multiple properties and an array can store multiple items. These are fundamental data structures that we can use to represent all kinds of information.
Here is an example of an array consisting of a series of objects. This array would likely be used by a programmer to represent an array of people.
Create a variable called movements that is an array of objects. Each object should have all of the following properties:
Define at least three different movements for your robot ball. As an extra challenge, see if you can get the ball to roll over all of the red platforms that now appear in the simulator.
If you're having trouble with this exercise, here are some common mistakes and hints to help you out:
| Mistake | Hint |
|---|---|
| Using parentheses instead of curly braces for objects | Objects must be created with { }, not ( ). Example: { color: "red", heading: 90, duration: 50, speed: 200 } |
| Forgetting commas between object properties | Each property in an object must be separated by a comma. Example: { color: "red", heading: 90, duration: 500, speed: 200 } |
| Using incorrect property names | Ensure the object properties are named exactly as specified: color, heading, duration, and speed. |