How to Get String Length in React JS?

Nov 03, 2022 . Admin

Hello Friends,

In this short tutorial we will cover how to get string length in react js. we will help you to give an example of get string length in react js. This tutorial will give you a simple example of find string length in react js. if you want to see an example of react js get string length then you are in the right place. So, let's follow a few step to create an example of react js get string length example.

In this example get string length in react js. I will step by step get string length in react js using str.length.

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';

const str = 'Mywebtuts.com';

const strLength = str.length;

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

Output:

13

I hope it can help you...

#React JS