I'm building angular2 app with TypeScript and i came across a problem (note that i'm a noob in angular2 and typescript).
Problem is identical to this: From an array of objects, extract value of a property as array but since i'm not using JavaScript, provided solution isn't very helpful (or is it?)
I'm getting JSON objects from API and simply save them in array:
constructor(private namelistService: NameListService) { }
getAllDevices(){
this.namelistService.getDevices()
.subscribe(
data => this.devices = data,
error => console.log('Server error'),
);
}
also my simple service:
constructor(private http:Http){}
getDevices(): Observable<any>{
return this.http.get("http://link-to-api")
.map( (res: Response) => res.json())
.catch((error: any) => Observable.throw(error.json().error || 'Server error'));
}
resulting in objects like this (i deleted the values):
{
"_id": "",
"info": {
"device_id": ,
"device_name": "",
"uid": "",
"firmware": "",
"hardware": "",
"description": ""
},
All i want to do is to get the _id values from every object in array and save it in seperate array: arr2 = [id1, id2, id3, id4, ... ]