Is there a way to add a number to each line of code?

Ok, so I’ve got this code:

const yaml = require('./yaml.json')
const num = 1


for (const [key, value] of Object.entries(yaml.uwu)) {
    console.log('{"'+ num +'":{"names":"' + value.characters + '","img_url":"https://elastictheme.org/wp-content/uploads/2014/10/comingsoon3.png","claims":"null","anime":"'+ key +'"}}')
    }

and I want it so num = the amount of lines there are plus 57.

So we would have this but instead of the one it would start at 58 then for each line after it would be 59, 60, 61 and so on. Is there a way I can do this?

(I don’t want it to be random)

At the beginning of the loop, you can try adding num++

That didn’t work :c

const values are constant - they can’t change.

Try changing your second line to let num = 1, then as CRJS suggests, put num++ inside the loop.
If you want it to start at 57 always, change the let statement to let num = 57

BUT

I remember from a previous converstaion that your data has numbered keys in it, which you’re probably pulling into the key variable. See what happens if you get rid of num entirely and put key in its place in your console log.

1 Like

Hahahaha, you were partially right, but this is me right now formatting waifu yaml data for my own database so the key isn’t the numbered. Anyways, thanks for telling me why, I completely forgot that I used const lol.