We're a place where coders share, stay up-to-date and grow their careers.
This seems like a prime example for the use of regexp:
/\b(?:Win|Mac|X11|Linux)/.test(navigator.appVersion) ? ({ Win: "Windows", Mac: "MacOS", X11: "UNIX", Linux: "Linux" })[RegExp.$1] : 'unknown'
Always improving! Nice one
How would I use this? For me, it returns undefined in both, Firefox and Chrome. The test itself returns true (as expected).
I would use match instead of test, because I also don't know how "test" should properly work in this case.
const OS = navigator.appVersion.match(/\b(?:Win|Mac|X11|Linux)/)[0]; console.log(OS);
Yeah match will work perfectly for this.
This seems like a prime example for the use of regexp:
Always improving! Nice one
How would I use this? For me, it returns undefined in both, Firefox and Chrome. The test itself returns true (as expected).
I would use match instead of test, because I also don't know how "test" should properly work in this case.
Yeah match will work perfectly for this.