在JavaScript/TypeScript中向数组末尾添加项

在JavaScript/TypeScript中向数组末尾添加项,javascript,typescript,Javascript,Typescript,我有这个做循环 trucks = []; fetchdata(){ this.trucks = []; do { this._reportService.getReports({ ..//pagination stuff here }) .subscribe(res=> { this.trucks.push(res.rawdatatrucks); }) } while(

我有这个做循环

trucks = [];
fetchdata(){
    this.trucks = [];

    do {

     this._reportService.getReports({
        ..//pagination stuff here
        })
        .subscribe(res=> {
          this.trucks.push(res.rawdatatrucks);
        })
    } while(i<this.totalRecords);
    console.log(this.trucks)

}
我希望得到的是在数组末尾附加数据,这样我就可以得到

console.log(this.trucks)

     0:[ ...truck data stuff ],
    1:[ ...truck data stuff ],
    2:[ ...truck data stuff ],
    3:[ ...truck data stuff ],
    4:[ ...truck data stuff ],
    5:[ ...truck data stuff ],
    6:[ ...truck data stuff ],
    .......
来自以下服务器的响应:

console.log(res.rawdatatrucks);
始终从0开始,即使在while循环的其他迭代中也是如此


我还需要向.push方法添加什么

使用
concat
而不是
push


this.trucks=this.trucks.concat(res.rawdatatrucks)

使用
concat
而不是
push


this.trucks=this.trucks.concat(res.rawdatatrucks)

concat无法工作。它将其保留为一个空的数组成员,
concat()
本身不会修改任何内容,它会返回一个新数组,您必须将该数组重新分配给
this.trucks
。concat无法工作。它将其保留为一个空的arrayRemember,
concat()
本身不会修改任何内容,它将返回一个新数组,您必须将该数组分配回
this.trucks
console.log(res.rawdatatrucks);