> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: menuItems()

# Method package: w

# Method menu location: w --> Menu --> menuItems

# Method Link: https://dev.wix.com/docs/velo/velo-only-apis/$w/menu/menu-items.md

# Method Description:

Sets or gets menu items.

Setting the `menuItems` property sets the items
 for a menu element.

 Getting the `menuItems` property returns a `menuItems` array of menu items that have been set using code. If no
 items have been set using code, the array defaults to the items defined using the Editor.

 You can't modify the `menuItems` array in-place. To add, change, or remove
 individual menu items:

   1. Store the value of the `menuItems` property in a variable.
   1. Make changes to the variable's array of items.
   1. Reset the `menuItems` property with the variable's modified array.

 To have the option for 2 additional submenus available for your horizontal menu, it must first be set 
 as an advanced menu. To set as an advanced menu, select the menu in the Velo editor, 
 click the Settings icon, and click on **Set as Advanced**.



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Get menu items

```javascript
let menuItems = $w('#myMenu').menuItems;

/* Sample array of menu items: 
 *
 * [
 *   {
 *     "link": "https://myairlines.com",
 *     "target": "_self",
 *     "label": "Home",
 *     "selected": true,
 *     "menuItems": []
 *   },
 *   {
 *     "link": "https://myairlines.com/reservations",
 *     "target": "_self",
 *     "label": "Book a Flight",
 *     "selected": false,
 *     "menuItems": []
 *   },
 *   {
 *     "link": "https://myairlines.com/frequentflier",
 *     "target": "_self",
 *     "label": "Mileage Program",
 *     "selected": false,
 *     "menuItems": [
 *       {
 *         "link": "https://myairlines.com//frequentflier/join",
 *         "target": "_self",
 *         "label": "Join",
 *         "selected": false,
 *         "menuItems": []
 *       },
 *       {
 *         "link": "https://myairlines.com/frequentflier/check",
 *         "target": "_self",
 *         "label": "Check Miles",
 *         "selected": false,
 *         "menuItems": []
 *       }
 *     ]
 *   }
 * ]
 */
```

## Set items for a horizontal menu

```javascript
$w('#myHorizontalMenu').menuItems = [
  {label: 'Home', link: '/', selected: true, id: 'item-id-1'},
  {label: 'For Rent', link: '/rentals', id: 'item-id-2'},
  {label: 'For Sale', link: '/purchases', id: 'item-id-3'},
  {label: 'Mortgage calculator', link: 'https://www.mortgagecalculator.org/', target: '_blank', id: 'item-id-4'},
  {label: 'About Us', link: '/about', id: 'item-id-5'}
];
```

## Set items for a vertical menu with a submenu

```javascript
$w('#myVerticalMenu').menuItems = [
  {label: 'Home', link: '/', selected: true},
  {label: 'For Rent', link: '/rentals', id: 'rentals-id', menuItems: [
    {label: 'Long Term', link: '/rentals/long', id: 'rentals-id-1'},
    {label: 'Short Term', link: '/rentals/short', id: 'rentals-id-2'}
  ]},
  {label: 'For Sale', link: '/purchases'},
  {label: 'Mortgage calculator', link: 'https://www.mortgagecalculator.org/', target: '_blank'},
  {label: 'About Us', link: '/about'}
];
```

## Set items for a menu that changes dynamically based on a visitor's role

```javascript
import { currentMember } from 'wix-members-frontend';

$w.onReady(async function  () {
  $w('#horizontalMenu').menuItems = [
    {label: 'Home', link: '/', selected: false},
    {label: 'For Rent', link: '/rentals'},
    {label: 'For Sale', link: '/purchases'}
  ]
  try {
    const roles = await currentMember.getRoles();
    const foundRole = roles.some(role => role.title === 'Realtor');
    if (foundRole) {
      let items = $w('#horizontalMenu').menuItems;
      items.push({
        label: 'Realtors Only',
        link: '/realtors'
      });
      $w('#horizontalMenu').menuItems = items;
    }
  } catch (error) {
    // Handle the error
    console.error(error);
  }
});

```

## Add a new menu item to an existing menu

```javascript
let menuItems = $w('#myMenu').menuItems;
menuItems.push({label: 'My New Label', link: '/mynewlink', id: 'my-new-id'});
$w('#myMenu').menuItems = menuItems;

```

## Use menu item ID for custom event behaviors

```javascript
import { openLightbox } from 'wix-window-frontend';

$w.onReady(function () {
  $w('#myMenu').menuItems = [{
    label: 'About us',
    id: 'about-id'
  }, {
    label: 'New collection',
    id: 'new-collection-id'
  }];

  $w('#myMenu').onItemClick(event => {
    if (event.item.id === 'new-collection-id') {
        openLightbox('Coming Soon');
    }
  }); 
});

```

---