After receiving a JSON result, which contains only one array as shown below:
{
id: "5",
client: "8",
}
id: 5
client: 8
I am trying to access it using the following function:
getClient(url: string){
this.clientService.client(this.clientUrl).subscribe((info: ClientInfo[]) => {
console.log(info);
console.log(info[0].id);
});
}
To retrieve the data within `.client`, I have created the public method as follows:
public client(url: string): Observable<ClientInfo[]> {
return this.httpClient.get<ClientInfo[]>(url);
}
The structure of the array being used is defined in the `ClientInfo` class:
export class ClientInfo{
id: number;
client: number;
}
Despite working with a single array, an error 'cannot get id of undefined' has been encountered. Is there any way to access the id value from this array? I've already attempted to use `info.id` but without success.