Issues with my Number formatting code in a repeater

Hello,
As the title suggests I have an issue with my number formatting code in my repeaters.
For some reason the formatting is interrupted and not executed every now and then… It happens when for example a filter is set or when you click the reset button. The very odd thing is that sometimes the formatting is applied only on some items and not on others.
See the screenshot below to better understand what I mean.

Please note that the price of the item to the left is not formatted but the item to the right is formatted correctly.

Here is the code I use right now:

$w.onReady(() => {
    $w("#bilarDataset").onReady(() => {
        $w('#carProductList').forEachItem( ($w, itemData, index) => {
        const numberWithCommas = (x) => {
        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
        }
    $w('#text68').text = numberWithCommas(parseInt($w('#text68').text)) + " kr";
        } );
    });
});

Any ideas to why this happens and what I should change in my code?

Many thanks in advance!
/Joe

You are using the global scope selector $w in the forEachItem() function. You should be using the repeated item scope selector $item as the documentation states.

Thanks for your reply.

I changed my code to this:

$w.onReady(() => {
    $w("#bilarDataset").onReady(() => {
        $w('#carProductList').forEachItem( ($item, itemData, index) => {
        const numberWithCommas = (x) => {
        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
        }
    $item('#saljpris1').text =         numberWithCommas(parseInt($item('#saljpris1').text))+" kr";
        } );
    });
});

However, the problem still occurs I’m afraid. Did I miss something?

As you can see the second and last item format accordingly but all the other items don’t for some reason… Any ideas?

Many thanks in advance!

I fixed it. Needed to set the repeater to onItemReady instead of forEachItem.

Many Thanks for your help Yisrael!