I use TypeScript for create array:
private menuItems: Menu[][];
After in loop I try to fill this like:
this.menuItems[role].push(this.menu[i]);
In result I want to get the following:
[1 : [{obj}, {obj}], 2: [{obj}, {obj}], 3: [{obj}, {obj}]]
What I do wrong?
Full code is:
public getMenuByRole(role: number): Menu[][] {
for ( let i = 0; i < this.menu.length; i++ ) {
if (this.menu[i].role === role && this.menu[i].avaliable) {
this.getTranslateMenuItem(this.menu[i].title).subscribe((translation: string) => {
this.menu[i].title = translation;
this.menuItems[role].push(this.menu[i]);
});
}
}
return this.menuItems;
}
Problem is that I try to add new objecti in array by custom key array, that is not exist
I tried also this:
const obj = {};
const arr = Array();
The in loop:
arr.push(this.menu[i]);
obj[role].push(arr);
this.menucontains? Maybe you can show some sample data.{1 : [{}. {}], 2: [{}, {}] }children: menuItem[]. This way you can build your menu graph without a complex array.