TypeScript for-of cikls
Ja mums ir nepieciešams atkārtot masīva elementus,
mēs izmantojam for-of ciklu.
Tomēr TypeScript ir viena nianse - mainīgā tips
elementam šajā ciklā netiek norādīts, jo TypeScript spēj
to automātiski noteikt:
let arr: number[] = [1, 2, 3, 4, 5];
for (let elem of arr) {
console.log(elem);
}
Pārrakstiet šādu kodu, izmantojot TypeScript:
let arr = [1, 2, 3, 4, 5];
let res = 0;
for (let elem of arr) {
res += elem;
}
console.log(res);