Hide/Show element on dynamic page based on the current event's categories

I’m having trouble with
I’m writing Velo/Javascript code in the $w.onReady() handler to hide/show an element on a dynamic page that shows a scheduled event. I would like to hide/show the element based on whether or not the event has a certain category assigned to it. (For example, show “Event ending soon!” if the “EndingSoon” category is set for that event.) Using code like:

    $w("#dynamicDataset").onReady(() => {
        // Get the current item from the dataset
        let currentItem = $w("#dynamicDataset").getCurrentItem();

	    console.log( "The categories are " + JSON.stringify(currentItem.categories));
   });

I can retrieve the event, but the categories field shows as an empty array, even though the event itself has multiple categories set. (If I display the currentItem contents, it shows proper values for the other fields.) Any ideas on how I can retrieve the categories for the event? Once I had the categories for the event, I could test to see if the one that I need is present and call show() or hide() on my element, but at the moment I am stuck on how to get the list.

Working in
Dev Mode

I figured out how to do this. The trick was that I needed to use the event’s ID to then look up the categories associated with that ID. The modified code looks like this:

import wixData from 'wix-data';
import { categories } from "wix-events.v2";



$w.onReady(function () 
   {
     $w('#image6').hide();
      $w("#dynamicDataset").onReady(() => {
        // Get the current item from the dataset

        let currentItem = $w("#dynamicDataset").getCurrentItem();

        categories.listEventCategories( currentItem._id)
          .then( (results) => {
            if ( results.categories.find( category => category.name === "Sale Ends Soon"))
            {
                console.log( "\n\n\n*** ITS SPECIAL ***\n\n\n");
                $w('#image6').show();
            }
          });

        });
   });

Hope this helps someone else who has a similar need.