Search code examples
arraysangulartypescriptjoinpush

How to push array into another non empty array in typescript? join if needed


this array contains atleast 10 objects

 array: any[] = [];

When a function is called, an array is expected to contain both existing and new objects from "item".

 function () {
    var timeline = this.service.fetchservice(10)
    .map((result : Response) => result.json())
    .subscribe(item=> {
          this.array.push(item);
        });
    }

error in console

ERROR TypeError: _this.array.push is not a function

Solution

  • something like:

     this.results = this.results.concat(data.results);