how to use {#each } with a number in Svelte

58 views Asked by At

I'm building a review site in Svelte, where users can rank restaurants with stars, and when I get the record back from the DB, I already know how many stars the restaurant has from each review. I would like to display the star image for each star.

For example, for a 3 star review, I would like to display 3 stars. What's the easiest way to dynamically populate a div with the star image?

Is there a way to do it using something like this? (in this example, StarNum is 3)

<div>
     {#each StarNum as star}
        <img src="img/star.png" />
     {/each}
</div>

Thanks!

0

There are 0 answers