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.
Nick HuemmerFront 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.
Hey Nick Huemmer,
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
write will only be removed from
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
Hope this helps!