React get array length

React.js

Nicesnippets

2299

15-05-2020


Hello Friends,

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 are going to explain how you can get the length of array. length is javascript method for count number of element in array. you can also get react state array length using this method.

Using this demo you can use the length method to count the number of items in an array. I want to know how many rows it's rendering. Get size of array returned by map in React render. react array length 0.

/src/ArrayLength.js

import React from 'react'

class ArrayLength extends React.Component{

render(){

var myArray = [1,2,3,4,5,6,7,8];

var result = myArray.length;

return(

<div>

<h4>Array length is { result }.</h4>

</div>

)

}

}

export default ArrayLength;

I hope it can help you...


Recommended Posts