How to know if a menuitem exists

I am creating a menu dynamically, is there a way to tell if a menuitem already exists so it does not get created a second time?

define “if a menuitem already exists” ?
is it just an item with the same name ? thats not a problem
same text caption ? again not an issue (bad UI but not a problem)
same keyboard shortcut as an existing one ? that will often give you weird results and the first one usually gets the keystroke

but in order to tell if one or more of these conditions exists you pretty much have to walk the menu(s) (and possibly the entire active menu bar in the case of keyboard shortcuts) to see

Use an integer property to store the state.
Initialise it with -1 and when you create your menu item and add it to the menu, store the index of where it is in the menu in the property so that it is easy to find afterwards.