I'm attempting to combine two arrays of the same type that are nested within a "parent" array. The end goal is to flatten the structure.
Below is the code I have been using:
ngOnInit() {
this.Logs.getAllLogs()
.subscribe(logs => {
this.Logs = Object.values(logs);
console.log('First: ', this.Logs[0]);
console.log('Second: ', this.Logs[1]);
this.mergedLogs = this.Logs[0].concat(this.Logs[1]);
console.log('Together: ', this.mergedLogs);
});
However, I encountered this error:
ERROR TypeError: _this.Logs[0].concat is not a function
UPDATE: After receiving suggestions from users to use a spread operator, I updated the code as follows:
ngOnInit() {
this.Logs.getAllLogs()
.subscribe(logs => {
this.Logs = Object.values(logs);
console.log('First: ', this.Logs[0]);
console.log('Second: ', this.Logs[1]);
this.mergedLogs = [...this.Logs[0], ...this.Logs[1]];
console.log('Together: ', this.mergedLogs);
});
}
Despite making these changes, I still encounter the same error. When I comment out the line where the arrays are merged, the page refreshes without issue, indicating it's not a caching problem.