Quiz: Destructuring Arrays (1-3)
Directions:
Use array destructuring to pull out the threecolorsfrom the array ofthings
and store them into the variablesone
,two
, andthree
.
Your Code:
/*
* Programming Quiz: Destructuring Arrays (1-3)
*
* Use destructuring to initialize the variables `one`, `two`, and `three`
* with the colors from the `things` array.
*/
const things = ['red', 'basketball', 'paperclip', 'green', 'computer', 'earth', 'udacity', 'blue', 'dogs'];
const one = things;
const two = '';
const three = '';
const colors = `List of Colors
1. ${one}
2. ${two}
3. ${three}`;
console.log(colors);
/* Solution */
const things = ['red', 'basketball', 'paperclip', 'green', 'computer', 'earth', 'udacity', 'blue', 'dogs'];
const [one,,,two,,,,three] = things;
const colors = `List of Colors
1. ${one}
2. ${two}
3. ${three}`;
console.log(colors);