⊗jsPmDstAEV 300 of 504 menu

Extra values during destructuring an array in JavaScript

If the array has less elements than variables, then undefined will be written into the "extra" variables:

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

If there are more elements in the array than variables, the extra elements will not be written anywhere and nothing bad will happen. For example, let's add hours, minutes and seconds to our array - nothing will change from this:

let arr = [2025, 12, 31, 23, 59, 59]; let [year, month, day] = arr; console.log(year); // shows 2025 console.log(month); // shows 12 console.log(day); // shows 31
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