Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Express Basics Parameters, Query Strings, and Modularizing Routes Using Data and Route Parameters

How can we have the first ID display as 1 instead of 0?

http://localhost:3000/cards/0 is the first card in the index, but wouldn't it be nicer to have it start at 1?

Is there a way to achieve this by adding +1 or something like that?

2 Answers

Simon Coates
Simon Coates
8,377 Points

Deduct 1. Maybe something like cards[req.params.id-1].question. However, I'd guess with any real world scenario, a database would probably generate the ids (might be able to configure where to start?) and the ids might be hidden inside anchor tags.

Heidi Fryzell
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Heidi Fryzell
Front End Web Development Treehouse Moderator 25,178 Points

Hello,

Cards is an array of objects that contain each cards flashcard data.

It is my understanding that the index of an array always starts with zero.

In the video when he selects cards[0].question, he is literally selecting the first object in the array, when he says card[0]. and then he is specifying the question property of that first object in the array.

It is just one of those things to you need to remember in programming, array indexes always start with zero.

Here is an article on medium explaining why array indexes start with zero.

https://medium.com/@albertkoz/why-does-array-start-with-index-0-65ffc07cbce8#:~:text=The%20most%20common%20answer%20to,comes%20from%20language%20design%20itself.&text=As%20we%20can%20see%20on,location%20of%20the%20array%20itself.

But you don't really need to know why you just need to remember that they do.

Good Question! Heidi

Hi Heidi,

Thanks for your reply. I think you're misunderstanding my question. I understand the index part but from a users perspective, someone who knows nothing about code or arrays, it's not intuitive going to the browsers address bar and typing 0. A typical user would start at 1.