Created
July 31, 2021 15:58
-
-
Save r2dev2/a01e185cd06e36efc574c2935c72ecdf to your computer and use it in GitHub Desktop.
Changing element of reactive array svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
let messages = [ | |
{ text: 'bru' }, | |
{ text: 'moment' }, | |
{ text: 'testing' }, | |
{ text: '123' }, | |
]; | |
let hideChoice = ''; | |
const hide = () => { | |
const i = parseInt(hideChoice); | |
const before = messages.slice(0, i); | |
const after = messages.slice(i + 1); | |
messages = [...before, { ...messages[i], text: 'hidden' }, ...after]; | |
}; | |
</script> | |
<input bind:value={hideChoice} /> | |
<button on:click={hide}> | |
Hide | |
</button> | |
{#each messages as msg, i} | |
<p>{msg.text}</p> | |
{/each} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment