I am using Angular 7 and I am getting this data from a service:
{name: "peter", datetime: 1557996975991}
Then I have this method that gets the 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
});
}
When I try to get the datatime value I'm getting:
Gives Error: Cannot read property 'datetime' of undefined
How can I fix this?
console.log(res.datetime)?