I have a map structure where key is array and values is objects.
myMap = new Map();
myMap.set(["_1030002", "_1030003"], { name: "Yayay", description: "aaa", floor: -3});
How to get values of objects by one key?
For example how to get value of 'floor' by key "_1030003"?
My provider store.ts:
import { HttpClient } from '@angular/common/http';
import { HttpClientModule } from '@angular/common/http'
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import { JsonStoresDataInterface } from './../../providers/stores/stores';
@Injectable()
export class StoresProvider {
private JsonStoresData = new Map();
defaultKey = "_1030003";
url_request = "path/to/json";
constructor(public http: HttpClient) {
}
getStoresRemote(){
this.http.get<JsonStoresDataInterface>(this.url_request).subscribe(data => {
var json = data.data;
for (var store of json.stores){
this.JsonStoresData.set(store.polygon_id, {
name: store.name,
description: store.description,
floor: store.floor[0],
image: store.pic_info.src,
uid: store.uid
})
}
});
console.log(this.JsonStoresData);//ok map
let keys = Array.from(this.JsonStoresData.keys());
let key = keys.find(key => key.includes(this.defaultKey));
console.log(this.JsonStoresData.get(key).floor);
//TypeError: Cannot read property 'floor' of undefined
}
}