Navigate back to the homepage

how to get length of array in react js?

Infinitbility
React
July 2nd, 2022 · 1 min read
how to get length of array in react js?

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To get the length of the array in react js, use the array length property it will return your array elements count.

The length property of an object which is an instance of type Array sets or returns the number of elements in that array. The value is an unsigned, 32-bit integer that is always numerically greater than the highest index in the array.

In the following example, we will take the sample array and use array length to get a count of the array elements.

1let arr = ["infinitbility", "aguidehub", "sortoutcode"];
2
3console.log(arr.length) // 3

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

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

In this example, we will do

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

In the above react js example, we have taken the sample array state, find the array 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 get length of object in react js?

how to get length of object in react js?

An example of find length of object in react js with a step-by-step example.

July 2nd, 2022 · 1 min read
how to find length of number in react js?

how to find length of number in react js?

An example of get length of number in react js with a step-by-step example.

July 1st, 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]