Route Parameters Question (‘/cards/:id’) (Example) | Treehouse Community

ok I understand.
I’ll try to explain it bit more.

Actually express does not know that we want to use the id from the URL as index. It is specified in the variables (const) below.
Just by having the “:id” in the route, express does not know what to do with that information.
You just take this parameter and then tell express, to use it as an index.
See the comments:

router.get('/:id', (req, res) => {

const { side } = req.query;

const { id } = req.params; // get the parameter "id" from the url and store it in the const called "id"

const text = cards[id][side]; // here we point to the cards array and use the id from "const id" as index.

const { hint } = cards[id];

res.render('card', {

....

...

So in other words, we are using the parameter “:id” and store the value in “const id = req.params.id” (or “const {id} = req.params” is the same).
Then we use the value from the “const id” and use it as index in cards. “cards[id]”

Back to your question:
Does adding a route parameter, regardless of what you name it, always reference the index values of the data held in the JSON file?
Answer: No, as long as you don’t tell express to use it as index, it’s not referring to any index.
And using the :id parameter as index is just in this example. It’s nothing mandatory to do it this way.

Did that answer your question? 🙂