How to get the length of the response from a fetch request?

How to get the length of the response from a fetch request?

I have got series of data that contains some objects in one array(json file) and it will be shown by react. Here is my code:

I have got series of data that contains some objects in one array(json file) and it will be shown by react. Here is my code:

 class App extends React.Component {
      constructor(props){
        super(props);
        this.state = {
        data: [],
        library:null,
        perPage: 20,
        currentPage: 1,
        maxPage: null,
        filter: ""
        };
       }
   componentDidMount() {
   fetch('/json.bc')
  // Here I want to get the length of my respose 
  .then(response => response.text())
  .then(text => {
  var Maindata = JSON.parse(text.replace(/\'/g, '"'))
   this.setState(state => ({
   ...state,
   data: Maindata
     }), () => {
     this.reorganiseLibrary()
    })
   }).catch(error => console.error(error))
}
  reorganiseLibrary = () => {
  const { filter, perPage , data } = this.state;
  let library = data;
    if (filter !== "") {
      library = library.filter(item =>
      item.hotelinfo.hotelsearch.realname.toLowerCase().includes(filter)
   );
 }

library = _.chunk(library, perPage); this.setState({ library, currentPage: 1, maxPage: library.length === 0 ? 1 : library.length }); }; // Previous Page previousPage = () => this.setState(prevState => ({ currentPage: prevState.currentPage - 1 })); // Next Page nextPage = () => this.setState(prevState => ({ currentPage: prevState.currentPage + 1 }));

// handle filter handleFilter = evt => this.setState( { filter: evt.target.value.toLowerCase() }, () => { this.reorganiseLibrary(); } ); // handle per page handlePerPage = (evt) => this.setState({ perPage: evt.target.value }, () => this.reorganiseLibrary());

// handle render of library renderLibrary = () => { const { library, currentPage } = this.state; if (!library || (library && library.length === 0)) { return <div class="tltnodata">no result!</div>; } return library[currentPage - 1].map((item, i) => ( <input type="hidden" value={item.hotelinfo.hotelsearch.hotelid} name="hotelid"/> )); };

render() { const { library, currentPage, perPage, maxPage } = this.state; return ( <div className="Main-wrapper"> <div class="filter_hotelname"><input value={this.state.filter} onChange={this.handleFilter} class="hotelName" /></div> <div class="countHotel"> <span class="numbersearch"></span> // Here I want two show the count of items </div> <div className="wrapper-data"> {this.renderLibrary()} </div> <div id="page-numbers"> <div class="nexprev"> {currentPage !== 1 && ( <button onClick={this.previousPage}><span class="fa-backward"></span></button> )} </div> <div className="data_page-info"> {this.state.currentPage} از {this.state.maxPage} </div> <div class="nexprev"> {(currentPage < maxPage) && ( <button onClick={this.nextPage}><span class="fa-forward"></span></button> )} </div>

  &lt;/div&gt;

</div> ); }
} ReactDOM.render(<App/>, document.getElementById('Result'));

I want to find the length of response from a request with fetch. Also I want to know how to find the count of items that will be shown by renderLibrary . For example in json.bc we have 4 objects I want to show 4 in numbersearch span.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Why ReactJS is better for Web Application Development?

Web Application Development is the point of contact for a business in today's digital era. It is important to choose the right platform for Web Application Development to build a high end Web

JSON Tutorial For Beginners | What is JSON | Learning JSON with JavaScript

JSON Tutorial For Beginners | What is JSON | Learning JSON with JavaScript

What is JSON - JSON Parsing in Swift

What is JSON and how do you parse JSON in Swift? JSON stands for JavaScript Object Notation and it's a way to represent data in a standard way. Learn how to parse JSON in Swift using the Codable protocol. We take the response JSON data from a real API call and then parse it in Swift!