Skip to content

Consider adopting for..of instead of each..as for iteration #4350

Closed
@samdesota

Description

@samdesota

Is your feature request related to a problem? Please describe.
I've been adopting svelte on a new project, really loving the simplicity of the design, with just enough power to make complex problems elegant.

One frustration as a beginner, the "each..as" syntax, which feels like it may have been inspired by PHP, feels out of place and I can't get my muscle memory to get the order right coming from JavaScript. Even after using svelte for a couple of weeks, I still write it backwards {#each item as items} almost every time and feels like a foreign construct in JavaScript land when the existing keywords "for..of" along with the reversed order feel they would be just as easy to use, but easier for JS developers.

I understand the declarative semantics are slightly more natural for each..as. In this case, however, I feel there would be less friction if Svelte used for..of.

Describe the solution you'd like
To make adoption easier and and to better meld with JS, introduce a new syntax:

{#for value of values}
{/for}

Which is exactly equivalent to

{#each values as value}
{/each}

Perhaps, if this is something that other users agree with strongly, the each syntax could be depreciated in a future version of Svelte.

How important is this feature to you?
Not critical obviously, but I believe it would make Svelte easier to adopt.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions