Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

weird issue when updating a value of an array in a object

$
0
0

Assume the following state object:

const state = writable({});$state = {value: ['a','b','c'], label: 'test'};

And replace one specific item of the array like this:

$state.value[1] = 'e';

Ok, no big deal so far. But then when I want to remove the last item of that array, like this:

const removeLastItem = function () {   $state.value = $state.value.pop();}

The above works until the changed item of the array is reached (i.e., only one iteration works in this example, so only the last 'c' value is removed, whereas the second and newly updated 'e' value seems impossible to remove).

Note that this behaviour only happens when an update to the array items occurs. Shall I use the spread operator to assign/replace the second value of the array?


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>