Create a menu subitems dynamically, bootstrap-4, css, javascript, jquery

I have a designed a Menu using CSS/Bootstrap in my application but submenus need to create runtime based on user role. Need function something like that take parameters to create a Menus Subitems created runtime. Please help me to how to achieve this scenario. Anyone’s help is appreciated

enter image description here

Source: Ask Javascript Questions