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 trial

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 26,840 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];

morningTasks.pop();

console.log(morningTasks);
console.log(allTasks);

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!