How to get the Android version of your device using JavaScript? (original) (raw)
Last Updated : 12 Jul, 2025
The task is to detect the Android version of the user with the help of JavaScript.
Two approaches are discussed here, the first example uses the **RegExp and the second uses **indexOf method to search the keyword ****'android'**.
**Note: Both codes will only work when you run them on Android devices.
**Approach 1: In this approach, we will use **navigator.useragent property, which returns the value of the user-agent header sent by the browser to the server. It contains information about the name, version, and platform of the browser. Then we need to search the keyword ****'android'** in the string returned and get the value in the temp array(which contains the version) to do that we will use a **RegExp. If the temp is not null then the value at index 0 is the answer else undefined.
**Example: This example implements the above approach.
html `