How to get the length of a number in JavaScript

Sometimes, you have to get the length of a number in Javascript. You can use the length property to get the length after toString() method which is used to convert the number into a string.

Answers 1
  • Get length of a number in Javascript

    <script>
    const val = 11111111111;
    const valLength = val.toString().length;
    console.log(valLength);
    </script>
    
    0

    You can get the length (count) of the characters of a number using .length property after toString() method in javascript.

    Output:

    11
  • Back to code snippet queries related javascript