Skip to content
Advertisement

How to handle foreach inside foreach?

I need to follow the concept of “DRY” So I have a lot of repetition in my code. decided to make it short as I can!

The design that I need to reach is: enter image description here

my shut:

JavaScript

The output of my code is:

enter image description here

Advertisement

Answer

Here we require two loops to display those menu and their sub menus. Try this

JavaScript

Output like this.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement