TypeScript, Looping through a dictionary TypeScript, Looping through a dictionary typescript typescript

TypeScript, Looping through a dictionary


To loop over the key/values, use a for in loop:

for (let key in myDictionary) {    let value = myDictionary[key];    // Use `key` and `value`}


< ES 2017:

Object.keys(obj).forEach(key => {  let value = obj[key];});

>= ES 2017:

Object.entries(obj).forEach(  ([key, value]) => console.log(key, value));


How about this?

for (let [key, value] of Object.entries(obj)) {    ...}