Show item in repeater depending on _createdDate

I’m looking to add a “new” label on item in my repeater that’s 5 days old and closer.

Right now I have this code, but it doesn’t show anything.

  const currentDate = new Date();
  const fiveDaysAgo = new Date();
  
  fiveDaysAgo.setDate(currentDate.getDate() - 5);

  $w("#repeater1").forEachItem(($item, itemData) => {
    const itemDate = itemData._createdDate; 
    if (itemDate >= fiveDaysAgo) {
      
      $item("#nouvelAjout").show();
    }
  });

Is forEachItem() being run before or after the repeater populates with data?

You might want to try onItemReady() which will fire whenever a new item is added to the repeater.

Also itemData._createdDate is going to come back as a string which I don’t think will compare correctly with a Date() so change this line:

const itemDate = Date.parse(itemData._createdDate);