⊗jstsPmBsLFO 12 of 55 menu

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);
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline