How to know if a user is on macOS using JavaScript

To know if a user is using macOS, you can check the navigator.platform property.

Example:

javascript
// Defining macOS devices
let macOS = ['iPhone', 'iPad', 'Mac', 'iPod'];

// Getting current operating system
let currentOS = navigator.platform;

// Checking if it's a Mac
let isMac = macOS.some(device => currentOS.includes(device));

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.