React: Difference between revisions

666 bytes added ,  30 September 2019
Line 274: Line 274:
console.log(last); // Rose
console.log(last); // Rose
console.log(peaks.join(", ")); // Rose, Ralston, Tallac
console.log(peaks.join(", ")); // Rose, Ralston, Tallac
</source>
Getting the rest of elements:
<source lang="js">
const lakes = ["Donner", "Marlette", "Fallen Leaf", "Cascade"];
const [first, ...others] = lakes;
console.log(others.join(", ")); // Marlette, Fallen Leaf, Cascade
</source>
function parameters:
<source lang="js">
function directions(...args) {
  let [start, ...remaining] = args;
  let [finish, ...stops] = remaining.reverse();
  console.log(`drive through ${args.length} towns`);
  console.log(`start in ${start}`);
  console.log(`the destination is ${finish}`);
  console.log(`stopping ${stops.length} times in between`);
}
directions("Truckee", "Tahoe City", "Sunnyside", "Homewood", "Tahoma");
</source>
</source>