I'm having a bit of a trouble right now in my Angular2 app. I've retrieved multiple objects from my service, thus i want to store each of them to their own class.
I know how to put an object to a class, however how to work it out if there are multiple objects?
My object
[
{
"_key": "2343200",
"_id": "test/2343200",
"_rev": "_U9JHQXa---",
"age": 10,
"name": "Soy"
},
{
"_key": "2342008",
"_id": "test/2342008",
"_rev": "_U9JGn0----",
"age": 20,
"name": "John"
},
{
"_key": "2342955",
"_id": "test/2342955",
"_rev": "_U9JG46u---",
"age": 32,
"name": "Jane"
}
]
Below is my class.
UserDetails.ts
export class UserDetails {
key: string;
id: string;
name: string;
age: number;
}
Using foreach()
could be the solution, but how to access each data if i want to manipulate them?
For example, i want to access the class of the second data.
Any kind of help is appreciated! I thank you in advance.
Edited: im using my apiservice to retrieve my datas.
data: any;
this.apiService.getUsers().subscribe(users=> {
this.data = users;
})