⊗jstsPmTpCh 23 of 55 menu

Modifying a Tuple in TypeScript

The elements of a tuple can be modified by writing values ​​of the appropriate type into them. Let's look at an example. Let's say we have the following tuple:

let user: [string, number] = ['john', 31];

Let's change its element:

user[0] = 'eric'; console.log(user);

But an attempt to write a value of a different type into a tuple element will result in an error:

user[0] = 12; //

Tell me what the result of running the following code will be:

let time: [number, number, number] = [12, 59, 59]; time[0] = 13; console.log(time);

Tell me what the result of running the following code will be:

let time: [number, number, number] = [12, 59, 59]; time[0] = '01'; console.log(time);
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