Instead of using object literal syntax to access nested values in objects, I'm trying to use es6 Map object, which has a convenient map.get()
method. I'm trying to avoid having to do the following with normal Javascript objects.
// access deeply nested values...
obj['k1'] &&
obj['k1']['k2'] &&
obj['k1']['k2']['k3']
Am I building the map wrong? only map.get('k1')
works (can't get nested map values, just the whole thing under k1: is given as a value).
var obj = {'k1': {'k2': {'k3': 'Test Value'}}};
const map = new Map(Object.entries(obj));
console.log(map.get('k1'));
console.log(map.get('k2'));
console.log(map.get('k3'));