ES6 snippet - JavaScript - Detect device type

PHOTO EMBED

Wed Nov 04 2020 08:44:06 GMT+0000 (Coordinated Universal Time)

Saved by @julien #javascript

const detectDeviceType = () =>
  /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
    ? 'Mobile'
    : 'Desktop';

// Example
detectDeviceType(); // "Mobile" or "Desktop"
content_copyCOPY

https://medium.com/swlh/24-modern-es6-code-snippets-to-solve-practical-js-problems-3609f301859e