'svelte - run code with side effects inside of for loop

I have the following Svelte component:

<script lang="ts">
    const tests = [ {txt: "aasdasdadss", foo: () => console.log("side ffect") }]
</script>
<div>
    {#each tests as test}
        <script>
            test.foo()
        </script>
        <div>{test.txt}</div>
    {/each}
</div>

Is there way to make test defined so, I can call foo?

This is closer, but it renders the null:

<script lang="ts">
    const tests = [ {txt: "aasdaasdasdsdadss", foo: null }]
    tests[0].foo = () => {
    }
</script>
<div>
    {#each tests as test}
        {
            test.foo() || null
        }
        <div>{test.txt}</div>
    {/each}
</div>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source