⊗jsPmDstASE 299 of 504 menu

Skipping array elements during destructuring in JavaScript

You can start writing to variables not from the beginning of the array, but skip some values. Let's skip the year, for example, and write the month and day into variables. To do this, when specifying variables, put a comma before the first variable, like this: [, month, day]:

let arr = [2025, 12, 31]; let [, month, day] = arr; console.log(month); // shows 12 console.log(day); // shows 31

You can skip not one value, but several:

let arr = [2025, 12, 31]; let [,, day] = arr; console.log(day); // shows 31

In the following code, parts of the array are written to the corresponding variables:

let arr = ['John', 'Smit', 'development', 'programmer', 2000]; let department = arr[2]; let position = arr[3];

Rework this code through destructuring according to the learned theory.

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