简体   繁体   中英

amount of returned values - REST API angular

I am using regular REST API with Angular like under the link: https://www.techiediaries.com/angular-by-example-httpclient-get/

In the function:

ngOnInit() {

    this.dataService.sendGetRequest().subscribe((data: any[])=>{
      console.log(data);
      this.products = data;
    })  
  }

can we get into data and get to know how many elements is returned?

I need to know how many elements are returned from backend.

The API returns array data: any[] . Javascript Array has length property which shows the total number of items in the array. All you need is to use data.length . If you are dealing with data, then you probably need to know the basics of Array: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

If data is an array simply use length property.

ngOnInit() {

    this.dataService.sendGetRequest().subscribe((data: any[])=>{
      console.log(data);
      this.products = data;
      this.productsLength = data.length;
    })  
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM