← Back to challenges

ES6: Destructuring Arrays I

JavaScriptMediumlanguage_fundamentalsarrays

Instructions

You can assign variables from arrays like this:

const arr = [1, 2, 3, 4, 5, 6]
let a = arr[0]
let b = arr[1]

console.log(a) // outputs 1
console.log(b) // outputs 2

With ES6, you can assign variables from arrays in a much more succinct way. Create variables a and b from the given array using the ES6 destructuring assignment syntax, where a === 1 and b === 2.

Notes

Check the Resources tab for examples.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Find Out the Leap Year