Javascript 返回值的数量-REST API角度

Javascript 返回值的数量-REST API角度,javascript,angular,Javascript,Angular,我正在使用常规REST API,链接下面有角度: 在函数中: ngOnInit() { this.dataService.sendGetRequest().subscribe((data: any[])=>{ console.log(data); this.products = data; }) } 我们可以进入数据并了解返回了多少元素吗 我需要知道从后端返回了多少个元素。API返回数组数据:any[]。Javascript数组具有len

我正在使用常规REST API,链接下面有角度:

在函数中:

ngOnInit() {

    this.dataService.sendGetRequest().subscribe((data: any[])=>{
      console.log(data);
      this.products = data;
    })  
  }
我们可以进入
数据
并了解返回了多少元素吗


我需要知道从后端返回了多少个元素。

API返回数组
数据:any[]
。Javascript数组具有
length
属性,该属性显示数组中的项目总数。您只需使用
data.length
。如果您正在处理数据,那么您可能需要了解数组的基本知识:

API返回数组
数据:any[]
。Javascript数组具有
length
属性,该属性显示数组中的项目总数。您只需使用
data.length
。如果您正在处理数据,那么您可能需要了解数组的基本知识:

如果数据是数组,只需使用length属性即可

ngOnInit() {

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

如果数据是数组,只需使用length属性

ngOnInit() {

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