How to Print Numbers Before Titles

Hey everyone, I just can’t seem to figure out how I’d add the number plus a period in front of each title. Would I use a nested loop?


You can do this nicely just using string interpolation and the i variable you are already using to power your loop. i starts at 0, so we want to do

for (let i = 0; i < titles.length; i++) {
  console.log(`${i+1}. ${titles[i]}`)

And this will print what you are looking for.

Ohhhhhhh so much less complicated than I thought! Thanks!

1 Like

The right answer often is, the simple things are always the hardest to remember I find!

1 Like