I need to know if it's possible to use the array.every method on multidimensional arrays.
My array looks like this:
tabs=[
{label: string, icon: icon, routerLink: link},
{label: string, icon: icon, routerLink: link},
{label: string, icon: icon, routerLink: link}]
I need to know whether every LABEL inside tabs is unequal to a specific label. I'd really appreciate it, if you could offer a detailed answer, since I'm a newbie-programmer and want to understand what I'm doing! But feel free to answer anyway. :) Thanks so far!
EDIT: I'm using this 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[] offered by primeng, tab is any.
Every time I doubleclick a chart, this one gets invoked an a new tab is pushed into my menu. Now I want to check wheter a tab with certain label is already opened, so that it does not open again. I tried using for loops combined with if
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)
}
}
But this opens a new Tab every time it is unequal, so that actually more then one tab gets opened on dblclick if there are more tabs already opened.
tabls.every((v) => v.label !== someValue)or!tabls.some((v) => v.label === someValue)tabs.every(function(item){ return item.label !== matchString})