You might consider filtering the members you want to display first, then displaying the length of the resulting array, and mapping over it to render the members:

Fiddle

render() {
    const membersToRender = this.state.members.filter(member => member.display)
    const numRows = membersToRender.length

    return (
      <div>
        <p>Number of rows = {numRows}</p>
        {
          membersToRender.map((member, index) => {
            return <p key={index}>{ member.name }</p>
          })
        }
      </div>
    );
  }

Edit: Thanks Edgar Henriquez, I fixed the key properties warning as you suggested

Answer from Michael Horn on Stack Overflow
🌐
Techiediaries
techiediaries.com › react-state-array-get-length-example
React state array: get length example |
The Array’s length property sets or returns the count of elements in the array. The obtained value is an unsigned 32-bit integer that is always greater than the array’s highest index. Create an index.js file and add the following code: import React from 'react' class App extends React.Component ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › length
Array: length - JavaScript | MDN
The length data property of an Array instance represents 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.
🌐
Medium
medium.com › @kashiyanivimal3333 › how-to-get-array-length-in-react-e4badb92bc83
How to Get Array Length in React? | by Kashiyani vimal | Medium
May 20, 2020 - We can use length method in react js for get length of array. many times rwe required array length for count. Here in this tutorial, we…
🌐
Squash
squash.io › accessing-array-length-in-thisstate-in-reactjs
Accessing Array Length in this.state in ReactJS
The simplest and most straightforward way to access the length of an array in this.state is by using the .length property. This property returns the number of elements in the array.
🌐
Altcademy
altcademy.com › blog › how-to-access-length-of-array-in-this-state-in-reactjs
How to access length of array in this.state in ReactJS
July 5, 2023 - In ReactJS, you might use an array to store multiple values or objects within your state. Now, what if you want to find out how many Lego blocks are in your box, or in other words, how many items are in your array? This is where the length property comes in.
🌐
GitHub
github.com › facebook › react › issues › 10383
Array length cannot be read · Issue #10383 · facebook/react
August 4, 2017 - Hello, I am new in React and I'm trying to run a piece of code, where I have the following function in which I use a for to iterrate an array. But after I run it,it gives me the error: Uncaught TypeError: Cannot read property 'length' of undefined. Can someone help me understand what is wrong with this?
Published   Aug 04, 2017
Find elsewhere
🌐
SPCAF
docs.rencore.com › spcaf › v7 › RCT010106_LengthPropertyCheckRule.html
SPCAF | Don't check the 'array.length' property when conditionally rendering elements
To avoid rendering empty arrays, you should explicitly check the array for items using array.length > 0. Bad practice · export class Tags extends React.Component { render() { return ( <div> {this.props.tags.length && `${this.props.tags.join(', ')}`} &nbsp; </div> ); } } Good practice
🌐
Snack
snack.expo.dev › @infinitbility › react-native-array-length
React native array length - Snack
Try this project on your phone! Use Expo's online editor to make changes and save your own copy.
🌐
Reddit
reddit.com › r/reactjs › console.log(array.length) gives 0 even though array has 6 nums(in render())??
r/reactjs on Reddit: console.log(array.length) gives 0 even though array has 6 nums(in render())??
October 27, 2020 -

hi i have this empty array which i pushed 6 numbers from 6 loops but when i try to get the array length in render, it gives back 0. Why is this so?

this is my function displayPokemons(ids) {
this.setState({txtStatus: "5"})
var results = [];
for (let id of ids) {
console.log("aa" + id);
this.getPokemonDetails(id).then(function(id) {
results.push(id)
})
this.setState({displayedPokemons2: results})
}}

and then in render
render() {

{console.log(this.state.displayedPokemons2)}
{console.log(this.state.displayedPokemons2.length)}

}

{console.log(this.state.displayedPokemons2)} gives me the 6 elements in the array
but {console.log(this.state.displayedPokemons2.length)} gives me 0.

🌐
Reddit
reddit.com › r/reactjs › array.length maximum
r/reactjs on Reddit: Array.length maximum
January 16, 2022 -

Soooo, I am developing an app in react, and one of the components is a history of search made by the user, and let's say I want to keep maximum of 5 elements in the array. The array is getting bigger each time the user clicks on an element. I tried to use for loop and map method but it didn't work as i wanted it to. You guys have any idea? cheers.

This is the logic for useState hook.

const historyHandler = (histValue) => {

setHistory((prevHistory) => { return [ ...prevHistory, { name: histValue, id: Math.random().toString(), }, ]; }); };

Here is the JSX in another component:

<Column>

<History history={history}></History> </Column>

And here is the component:

export const History = (props) => {

return ( <Container>

<h3>History:</h3>
<ul className="history">
{props.history.map((point) => (
<li key={point.id}>{point.name}</li>
))}
</ul>
</Container>
);
};

Any feedback would be useful :)

🌐
Bobby Hadz
bobbyhadz.com › blog › react-check-if-array-is-empty
Check if an Array or a String is Empty in React | bobbyhadz
To check if an array is empty in React, access its `length` property, e.g. `arr.length`. If an array's length is equal to `0`, then it is empty.