After the last video, the van’s load is right again: closedDocks.includes(name) keeps Market Hall off the list, and Elm Street gets its six bikes.
The dock data itself is still in loose pieces, though: Harbor Square’s numbers as single values, and the five bike counts as the array [0, 14, 6, 0, 11]. Nothing in that array says the first 0 belongs to Elm Street, or that Elm Street has 12 free slots, yet each line of the report needs a dock’s name, bikes, and slots together.
The Python script never had that problem, because it keeps each dock as one dictionary. In this lesson, you’ll write a dock as one JavaScript record and the whole dock list as a list of records, the shape the report’s data takes from here on. Start with a single dock.
Write a Dock as an Object
In Python, a dock is a dictionary with three known keys, and the script reads each value by its key in square brackets:
dock = {"name": "Elm Street", "bikes": 0, "slots": 12}
print(f"{dock['name']} has {dock['bikes']} bikes")