4 ms·
Each loops over anything with a length property: {#each {length: 3} as _, i} https://stackoverflow.com/questions/58213585/svelte-3-how-to-loop-each-block-
by arve0 3y ago
Each loops over anything with a length property:
{#each {length: 3} as _, i}
https://stackoverflow.com/questions/58213585/svelte-3-how-to-loop-each-block-x-amount-of-times https://stackoverflow.com/questions/58213585/svelte-3-how-to...
- jchw 3y agoThat's not really a huge improvement over just making a sparse array though, is it? Looks more confusing to me. Could be wrong but I'm pretty sure e.g. Array(1000000000) does not actually allocate much.
- arve0 3y agoI'm not up to speed in JSX, how is it be better there? Don't one normally map over an array to loop? You cannot use for-loops inside JSX? Or do you create an array of JSX-elements, like let elements=[] for (let i=0; i < 10; i++) { elements.push(<li key={i}>I'm number {i}</li>) } return <ol>{elements}</ol>; Does not seem like an improvement to me.
- jchw 3y agoIt's just JS: You can do that, or you can use any helper method, or write your own helper. Can't really do that in Svelte.