---
title: "How to find the operating system details using JavaScript?"  
description: "How to find the operating system details using JavaScript?"  
author: "Utpal Vishwas"  
published: 2023-07-13  
updated: 2023-07-14  
canonical: https://www.mindstick.com/forum/159066/how-to-find-the-operating-system-details-using-javascript  
category: "javascript"  
tags: ["javascript", "operating system"]  
reading_time: 2 minutes  

---

# How to find the operating system details using JavaScript?

How to find the [operating system](https://www.mindstick.com/articles/229069/operating-system-development) details using [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)?

## Replies

### Reply by Aryan Kumar

Sure, here is how to find the OS details using JavaScript:

JavaScript

```plaintext
// Get the user agent string.
const userAgent = navigator.userAgent;

// Extract the OS name and version.
const osDetails = userAgent.match(/(Windows|Linux|Mac|Android|iOS)\s+(.*)/);

// If the OS details are not found, return undefined.
if (!osDetails) {
    return undefined;
}

// Return the OS details.
return {
    osName: osDetails[1],
    osVersion: osDetails[2],
};
```

This code will first get the user agent string from the `navigator` object. The user agent string is a string that identifies the browser and operating [system](https://www.mindstick.com/articles/23411/the-most-effective-method-to-find-the-perfect-small-business-phone-system-for-your-business) that the user is using.

Next, the code will use the `match()` method to extract the OS name and version from the user agent string. The `match()` method takes a regular expression as an argument and returns an array of matches if the regular expression matches the string.

The regular expression in this code matches the following strings:

- `Windows <version>`
- `Linux <version>`
- `Mac <version>`
- `Android <version>`
- `iOS <version>`

If the regular expression does not match the user agent string, the `match()` method will return an empty array.

Finally, the code will return the OS details if they were found. If the OS details were not found, the code will return `undefined`.

Here is an example of how to use this code:

JavaScript

```plaintext
const osDetails = getOSDetails();

if (osDetails) {
    console.log(`OS name: ${osDetails.osName}`);
    console.log(`OS version: ${osDetails.osVersion}`);
} else {
    console.log(`OS details could not be found.`);
}
```

This code will first call the `getOSDetails()` function to get the OS details. If the OS details are found, the code will log the OS name and version to the console. If the OS details are not found, the code will log a message to the console.


---

Original Source: https://www.mindstick.com/forum/159066/how-to-find-the-operating-system-details-using-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
