← Back to challenges

Destructuring Assignment (Ignoring Values)

JavaScriptHardlanguage_fundamentalsloopslogic

Instructions

You can assign variables from arrays like this:

arr = [1, 2, 8]
first, , last = arr

first = lst[0]

last = lst[arr.length - 1]

console.log(first) ➞ outputs 1
console.log(last) ➞ outputs 8

Using Destructuring Assignment, your task is to unpack the arrays writeyourcodehere into three variables, first, a variable to ignore all middle values and last.

Notes

  • Your solution should be just One Line of code.

  • Another version of this challenge.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Skip the Drinks with Too Much Sugar