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
.a{fill-rule:evenodd;}techdegree seal-36
Nick Huemmer
Front End Web Development Techdegree Graduate 22,037 Points

Why does this return six items instead of 5?

Is it because the .pop() method is not working because no value is specified? It seems like "write" should be removed from the morning tasks array.

When I run this code in my console I get six items in the combined array. Interesting.

1 Answer

Hey Nick Huemmer,

The length value of allTasks will always remain six even if you add/remove items. That's because spread syntax creates a copy of the morningTasks array. So when you use pop() method, write will only be removed from morningTasks array.

const morningTasks = [ 'study', 'exercise', 'write' ];
const eveningTasks = [ 'bake', 'edit article',  'chill' ];
const allTasks = [...morningTasks, ...eveningTasks];



If you log the value of morningTasks it will output: ['study', 'exercise']

And if you log the value of allTasks it will output: ['study', 'exercise', 'write', 'bake', 'edit article', 'chill']

To learn more about spread operator, check out this website: https://basarat.gitbook.io/typescript/future-javascript/spread-operator

Hope this helps!