Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNick Huemmer
Front End Web Development Techdegree Graduate 26,840 PointsI can't figure out the solution to this quiz - none the methods I've learned fit into this notation.
const itemsA = [ 'Lightsaber', 'Mockingjay pin', 'Box of chocolates' ];
const itemsB = [ 'Ghost trap', 'The One Ring', 'DeLorean' ];
const allItems = itemsA.concat(itemsB);
Is how it seems the answer should be written, based on what we've learned in the lessons.
We could also do
const itemsA = [ 'Lightsaber', 'Mockingjay pin', 'Box of chocolates' ];
const itemsB = [ 'Ghost trap', 'The One Ring', 'DeLorean' ];
const allItems = itemsA.join(itemsB);
Neither of which will fit into the answer slots here. What am I missing?
1 Answer
Adam Pengh
29,881 PointsYou can use the spread operator to copy over all elements of each array.
const itemsA = [ 'Lightsaber', 'Mockingjay pin', 'Box of chocolates' ];
const itemsB = [ 'Ghost trap', 'The One Ring', 'DeLorean' ]
const allItems = [ ...itemsA, ...itemsB ];
Nick Huemmer
Front End Web Development Techdegree Graduate 26,840 PointsGot it, thanks Adam!
Nick Huemmer
Front End Web Development Techdegree Graduate 26,840 PointsNick Huemmer
Front End Web Development Techdegree Graduate 26,840 PointsHa ha, nevermind.
I just realized the answer uses the spread method.
...itemsA, ...itemsB
.