Accessing nested properties with dynamic property name Accessing nested properties with dynamic property name json json

Accessing nested properties with dynamic property name


You can use Object.keys() to get the array of keys, but instead of for...loop I suggest to iterate over the array of keys with Array.prototype.forEach().

Code:

const obj = {"data": {"Meta Data": {"1. Information": "Monthly Prices (open, high, low, close) and Volumes","2. Symbol": "MSFT","3. Last Refreshed": "2017-08-18","4. Time Zone": "US/Eastern"},"Monthly Time Series": {"2017-08-18": {"1. open": "73.1000","2. high": "74.1000","3. low": "71.2800","4. close": "72.4900","5. volume": "285933387"},"2017-07-31": {"1. open": "69.3300","2. high": "74.4200","3. low": "68.0200","4. close": "72.7000","5. volume": "451248934"}}}};Object  .keys(obj.data['Monthly Time Series'])  .forEach(function (k) {    console.log(obj.data['Monthly Time Series'][k]['1. open']);  });