How to Convert String to Number in React JS?

Nov 05, 2022 . Admin

Hello Friends,

This article will give you an example of how to convert string to number in react js. you can see convert string to a number in react js. it's a simple example of react js convert string to a number. I explained simply about react js convert string to number example. Let's see bellow example convert string to number using react js.

In this example convert string to number in react js. I will step by step convert string to number using parseInt() react js. React js provides various ways to convert a string value into a number.

So, let's start following example:

Step 1: Create React JS App

In this step, open your terminal and execute the following command on your terminal to create a new react app:

npx create-react-app reactjs-my-example
Step 2: Create index.js file src/index.js
import React from 'react';
import ReactDOM from 'react-dom/client';

// create string
const count = parseInt('1234', 10);

const App = () => {
    return (
        <div>
            <h1>{count}</h1>
        </div>
    );
}
  
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
Run React JS App:
npm start

Output:

1234

I hope it can help you...

#React JS