CJCoding With Joseph
← Back to Question List
JavaScript Code Walkthrough #34

Destructuring with Rest

hardArrays

📄 Code

Read carefully — what does this print?
1let arr = [1, 2, 3, 4];
2let [first, second, ...rest] = arr;
3console.log(first + " " + second);
4console.log(rest.length);
5let combined = [...rest, first];
6console.log(combined.join(","));

🎯 Your Answer