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.

let arr = ["infinitbility", "aguidehub", "sortoutcode"];

console.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
import React, { useState, useEffect } from "react";
import "./styles.css";
export default function App() {
  const [sampleArray, setSampleArray] = useState(["infinitbility", "aguidehub", "sortoutcode"]);

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

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 👍.