Change date output format in a repeater

Thank you to everybody for the tips I got.
I found the solution after some trials. The problem is that the second date field in the collection is not allways recorded (empty). Therefore I have to check that date field for the values “null” and “undefined” to prevent an error on the date conversion. The following code now runs like expected:

import wixData from ‘wix-data’;
$w.onReady(function () {
$w(“#dsEventsYear”).onReady( () => {
// get data from the dataset for each repeater item
$w(“#repeater1”).forEachItem( ($item, itemData, index) => {
// Get the start date from the date fields of the current item
let originalStartDate = itemData.startDate;
let originalEndDate = itemData.endDate;
console.log(“original start date: " + originalStartDate)
console.log(“original end date: " + originalEndDate)
// convert start date to local format
let convertedStartDate = originalStartDate.toLocaleDateString(“DE-ch”);
$item(”#startDate”).text = convertedStartDate;

  if (originalEndDate === null || originalEndDate === undefined) { 
     console.log("original end date is empty"); 
     $item("#titleEndDate").collapse(); 
     $item("#endDate").collapse(); 
     } 
  else { 
    let convertedEndDate = originalEndDate.toLocaleDateString("DE-ch"); 
    console.log ("converted end date: " + convertedEndDate); 
    $item("#endDate").text = convertedEndDate; 
    $item("#titleEndDate").expand(); 
    $item("#endDate").expand(); 
    } 
} ); 

} );
} );