S SmartDocs
系列: JavaScript javascript 8 行 · 更新于 2026-02-03

exercise1.js

JavaScript/modules/module2-intermediate/code-examples/lesson2/exercise1.js

// Exercise 1: Array Destructuring
let fruits = ["apple", "banana", "orange", "grape", "kiwi"];
let [first, , third, ...rest] = fruits;
let last = rest[rest.length - 1];

console.log("First:", first);   // "apple"
console.log("Third:", third);  // "orange"
console.log("Last:", last);    // "kiwi"

相关文章