Skip to content

Instantly share code, notes, and snippets.

@jpalala
Created April 17, 2020 23:46
Show Gist options
  • Save jpalala/ff28bbea346ba3f4dd086cdfc28e0c06 to your computer and use it in GitHub Desktop.
Save jpalala/ff28bbea346ba3f4dd086cdfc28e0c06 to your computer and use it in GitHub Desktop.
svelte-todo
<script>
let todos = [];
function addTodo() {
todos = [...todos, ''];
}
function removeSelf(index) {
todos = [...todos.slice(0, index), ...todos.slice(index + 1)]
}
</script>
{#each todos as todo, index}
<input bind:value={todos[index]}>
<button on:click={() => removeSelf(index)}>&#x2717</button>
<br>
{/each}
<button on:click{addTodo}>Add</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment