The for-of loop in TypeScript
If we need to iterate over the elements of an array, we use the for-of cycle. However, there is one nuance in TypeScript - the variable type for the element in this cycle is not specified, since TypeScript is able to calculate it automatically:
let arr: number[] = [1, 2, 3, 4, 5];
for (let elem of arr) {
console.log(elem);
}
Rewrite the following code using TypeScript:
let arr = [1, 2, 3, 4, 5];
let res = 0;
for (let elem of arr) {
res += elem;
}
console.log(res);