You need to either use the function:
myarray.days.forEach((obj, index) => { console.log('before transform, this : ' + this); this.datePipe.transform... });
Or use the binding method :
myarray.days.forEach(function(obj, index) { console.log('before transform, this : ' + this); this.datePipe.transform... }.bind(this));
The reason is that when passing a regular function as a callback when it is called, this is not actually saved.
The two methods that I mentioned above will ensure that the scope of this right is preserved for future execution of the function.
source share