Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Arrays Multidimensional Arrays Review JavaScript Arrays

Nick Huemmer
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Nick Huemmer
Front End Web Development Techdegree Graduate 22,037 Points

I 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
Adam Pengh
29,877 Points

You 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 ];