Destructuring Assignment (Ignoring Values)

Published by Werdna in

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 (check the Resources tab), 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.
  • If your solution is longer than one line of code, please check the Resources tab.
  • Another version of this challenge.
Watch a quick demo on how Edabit works.