Stelve For Loop
Svelte offers us a great each structure for repeatable elements. E.g;
<script>
let names = ['phpexample', 'jack', 'daniels']
</script>
<ul>
{#each names as name (name)}
<li>{name}</li>
{/each}
</ul>
But what if we had a block that repeated based on the number held in a variable? Svelte does not provide us any convenience regarding the for loop :/ What can we do?
We can perform our operation by creating an array of n with Array(n) and inserting it into each. E.g;
<script>
let rows = 5
</script>
<ul>
{#each Array(rows) as _, row (row)}
<li>{row}. Line</li>
{/each}
</ul>
this much, good work.
Comments
Popular Articles
Popular Tags
- #directive
- #Function
- #Json
- #Class
- #SASS
- #Form
- #Redirect
- #API
- #Special Characters
- #Special
- #Random
- #Generating
- #
- #Text
- #Ajax
- #URL
- #Encrypting
- #React
- #Show
- #timeAgo
- #PSR-4
- #Hide
- #DDOS Protection
- #DDOS
- #cURL
- #Logic For Displaying Posts
- #Error
- #Key
- #General Error
- #1364 Field
- #Abbreviation
- #Blade
- #Version
- #QR
- #QR Code Generating
- #Array
- #Arrays with Key Values to String Statement
- #Short Tag
- #Activate
- #Real Time
- #Socket.io
- #301
- #Custom Directives
- #Iframe Detection
- #Date
- #Characters
- #Insert
- #Autoloader
- #Composer
- #Reading
There are no comments, make the firs comment