The for-in loop in TypeScript
We can iterate over the elements of an object using the for-in cycle. In this case, the variable type for the key is not specified:
let obj = {a: 1, b: 2, c: 3};
for (let key in obj) {
console.log(key);
}
Rewrite the following code using TypeScript:
let obj = {a: 1, b: 2, c: 3};
let res = 0;
for (let key in obj) {
let elem = obj[key];
res += elem;
}
console.log(res);