I am trying to concat two arrays of the same type together. The two arrays are actually nested in a "parent" array. So, the goal is to just flatten it out.
This is the code that I am 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);
}); }
But I am getting this error:
ERROR TypeError: _this.Logs[0].concat is not a function
EDIT: Some users suggested to use a spread operator, so the code was then changed to:
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);
});
}
But somehow I still get the same exact error. When I comment out the line where the arrays are merged, the page refreshes fine, so it is not a caching issue.
this.Logsis an array of arrays? I find it a bit strange, can you post a console.log of it?