I have an array of JSON and want to paste it into an array variable in typescript.
the JSON I receive from http://www.example.com/select.php:
{
"User":[
{"Name":"Luca M","ID":"1"},
{"Name":"Tim S","ID":"2"},
{"Name":"Lucas W","ID":"3"}
]
}
I would like to get an array like that:
this.items = [
'Luca M',
'Tim S',
'Lucas W'
];
EDIT:
current code is
this.http.post('http://www.example.com/select.php', creds, {
headers: headers
})
.map(res => res.json().User)
.subscribe(
data => this.data = data.User.map(user => user.Name),
err => this.logError(err),
() => console.log('Completed')
);
this.items = this.data;
error:
Cannot read property 'map' of undefined
how can I realize this?
Thanks and best regards