merge two object arrays with Angular 2 and TypeScript? merge two object arrays with Angular 2 and TypeScript? arrays arrays

merge two object arrays with Angular 2 and TypeScript?


The spread operator is kinda cool.

this.results = [ ...this.results, ...data.results];

The spread operator allows you to easily place an expanded version of an array into another array.

You can read about spread operator here.


I think that you should use rather the following:

data => {  this.results = this.results.concat(data.results);  this._next = data.next;},

From the concat doc:

The concat() method returns a new array comprised of the array on which it is called joined with the array(s) and/or value(s) provided as arguments.


With angular 6 spread operator and concat not work. You can resolve it easy:

result.push(...data);