Hacker News new | past | comments | ask | show | jobs | submit login

Each loops over anything with a length property:

    {#each {length: 3} as _, i}
https://stackoverflow.com/questions/58213585/svelte-3-how-to...



That'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.


I'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.


It'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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: