Is it possible to use the array.every method on multidimensional arrays?
The structure of my array is as follows:
tabs=[
{label: string, icon: icon, routerLink: link},
{label: string, icon: icon, routerLink: link},
{label: string, icon: icon, routerLink: link}]
I am trying to determine if every LABEL within tabs is different from a specific label. I would appreciate a detailed explanation since I am new to programming and keen on understanding the process! But any answer is welcome. :) Thank you in advance!
EDIT: I am using the following method to add Tabs to my Tabmenu(ng2, primeng):
addTab(id: string) {
if (id === 'linechart') {
this.tab = {
label: 'NW-Details',
icon: 'fa-area-chart',
routerLink: ['/nwdetails']
}
TABS.push(this.tab);
}
if (id === 'piechart') {
this.tab = {
label: 'IO-Details',
icon: 'fa-pencil',
routerLink: ['/iodetails']
}
TABS.push(this.tab)
}
}
Whereas TABS is typeof MenuItem[] provided by primeng, tab is any.
Whenever I double-click on a chart, this function is called and a new tab is added to my menu. Now I want to check if a tab with a certain label is already open to prevent opening it again. I have tried using for loops combined with if statements
for (i = 0; i < TABS.length; i++) {
if (TABS[i].label !== 'NW-Details') {
this.tab = {
label: 'NW - Details',
icon: 'fa - area - chart'
TABS.push(this.tab)
}
}
However, this results in opening a new tab each time it is not equal, causing multiple tabs to be opened upon double-clicking when there are existing tabs.