index of an item in repeater not showing

Hi ,
I have a repeater connected to a database and the following code onClick of a button

$w(“#repeater1”).onItemReady(() =>{
let itemIndex = $w(“#dataset1”).getCurrentItemIndex();
$w(“#index”).text = itemIndex.toString();
});

So, Once clicked, I’ll have the index of items to use as Serial Numbers. But, the above function doesn’t work and the $w(“#index”).text shows only 0.

How can I correct this?

Found an easy way here : https://www.wix.com/corvid/forum/community-discussion/serial-number-in-repeater