⊗jstsPmBsLFI 13 of 55 menu

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);
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