Hi Friends 👋,

Welcome To Infinitbility! ❤️

To get the length of the number in react js, convert the number to string using the toString() method and use the String length property it will return of your number char count.

The length property of a String object contains the length of the string, in UTF-16 code units. length is a read-only data property of string instances.

In the following example, we will take the sample number, convert it into string and use string length to get the length of your number.

let num = 22897878434;

console.log(num.toString().length) // 11

Today, I’m going to show you How do i find the length of the integer in react js, as above mentioned here, I’m going to use the toString() method, and the String length property.

Let’s start today’s tutorial how do you get the length of the number in react js?

In this example, we will do

  1. take an example of a number state
  2. use the toString() method, and string length
  3. print the length of the number on the page screen
import React, { useState, useEffect } from "react";
import "./styles.css";
export default function App() {
  const [sampleNumber, setSampleNumber] = useState(35465734535);

  return (
    <div className="App">
      <h1>{`sampleNumber length is ${sampleNumber.toString().length}`}</h1>

In the above react js example, we have taken the sample number state, used string toString() and string length, and printed it on the screen.

I hope it helps you, All the best 👍.