Q:

How to create static(hard coded) nested Array data in Typescript

I want to create multilevel dropdown list in Angular. For that I need static data of type below
Item1
Item2
    SubItem1
    SubItem2
Item3
Item4
    SubItem14
    SubItem15
Item5

I Typescript, how can I create this data(hard coded) using array?
I have tried like this
public arrayname: string[] = ["Item1", "Item2", "Item3"];

but that is not nested.

A:

You can use array of objects instead of array of string, like
interface Item {
    name: string;
    subItems: string[]
}

let dropdown: Item[] = [
{
    name: "Item1", 
    subItems: []
}, 
{
    name: "Item2", 
    subItems: ["SubItem1", "SubItem2"]
}
];

Now you can traverse dropdown array to pupulate menu and for each item traverse subItems to populate submenu
Update :
interface Item {
    label: string;
    icon: string;
    link?: string;
    items?: Item[]
}

let dropdown = [
{
    label: "Item1", 
    icon: " icon"
}, 
{
    label: "Item2", 
    icon": " icon2", 
    items: [
        {
            label: "subitem", 
            icon: " icon", 
            link: "link", 
        }
    ]
}
];

Now by this solution you can nest any no of times

