As I examine an object,
links = {
link1: 'page1',
link2: 'page2',
link3: 'page3',
link4: 'page4',
link5: 'page5',
link6: 'page6'
}
I possess a function for retrieving the page URL through the router
Within this function, I make use of Object.keys to loop through the object values. If any value matches, it should assign other variables accordingly.
Although I aim to utilize a ternary statement, its functionality perplexes me at present. Can anyone shed some light on this matter?
A regular if statement does produce the desired outcome...
private fetchPages(): void {
this.subscriptions = this.router.events
.pipe(
filter((event) => event instanceof NavigationEnd)
)
.subscribe((event) => {
let position: number;
let located: boolean;
Object.keys(this.links).map((key, i) => {
if (this.links[key] === event['url']){
// This is effective
located = true;
more details....
}
// The following approach falls short
event['url'] === this.links[key] ? (located = true, position = i) : (located = false, position = 0)
});
});
}