Using Objects as Dicts and Records

The closed-dock check now uses .includes(). The report still needs each dock’s name, bikes, and slots together. [0, 14, 6, 0, 11] alone can’t identify Elm Street or its twelve free slots. Carry your Python records across so you can build each report line from a complete dock record.

Write a Dock as an Object

In Python, you’d read the dock’s known keys from a dict:

Language: Python
dock = {"name": "Elm Street", "bikes": 0, "slots": 12}
print(f"{dock['name']} has {dock['bikes']} bikes")

In JavaScript, write the record as an object literal, braces containing named values called properties. console.log() prints its arguments:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.