Navigate back to the homepage

how to find length of string in react js?

Infinitbility
React
July 1st, 2022 · 1 min read
how to find length of string in react js?

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To get the length of the string in react js, use the String length property it will return your string 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 string and use string length to get a count of the string.

1let str = "infinitbility";
2
3console.log(str.length) // 13

Today, I’m going to show you How do i find the length of a string in react js, as mentioned above here, I’m going to use the use String length property.

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

In this example, we will do

  1. take an example of string state
  2. use the string length
  3. print the length of string on the page screen
1import React, { useState, useEffect } from "react";
2import "./styles.css";
3export default function App() {
4 const [sampleString, setSampleString] = useState("infinitbility");
5
6 return (
7 <div className="App">
8 <h1>{`infinitbility length is ${sampleString.length}`}</h1>
9 </div>
10 );
11}

In the above react js example, we have taken the sample string state, find the string length, and print it on the screen.

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to convert json object to string in react js?

how to convert json object to string in react js?

An example of convert json object to string in react js with a step-by-step example.

June 30th, 2022 · 1 min read
how to get first character of string react js?

how to get first character of string react js?

An example of get first character of string react js with step by step guide.

June 29th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]