In my Angular 7 project, I am retrieving data from a service which looks like this:
{name: "peter", datetime: 1557996975991}
I have a method that is supposed to retrieve this data:
myMethod() {
this.myService.getdata().subscribe((res) => {
console.log(res); // returns: {name: "peter", datetime: 1557996975991}
console.log(res[0].datatime); // Gives Error: Cannot read property 'datetime' of undefined
});
}
However, when I attempt to access the 'datatime' value, I encounter this error:
Error: Cannot read property 'datetime' of undefined
How can I solve this issue?