⊗jsPmDstAR 301 of 504 menu

Remaining part of an array when destructuring in JavaScript

If the array has more elements than variables, if necessary, extra elements can be written to the array using the rest operator:

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

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

let arr = ['John', 'Smit', 'development', 'programmer', 2000]; let name = arr[0]; let surname = arr[1]; let info = arr.slice(2); // all elements from the second to the end of the array

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