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 Store Multiple Values in an Array Review Adding, Removing, and Copying Array Elements

Complete the code below to add the value 23 the the beginning of the ages array

i thouight the answer would be ages.push (...23)but that is not the answer.

Reggie Williams
Reggie Williams
Treehouse Teacher

Hey Alana Warson the push method adds elements to the end of an array and you don't need the spread operator here. try reviewing this video to find the method that adds items to the beginning of the array.

2 Answers

Hi Alana!

You want this:

unshift(23);

Keep in mind:

1) shift REMOVES an item from the BEGINNING of an array.

2) unshift ADDS an item to the BEGINNING of an array.

3) pop REMOVES an item from the END of an array.

4) push ADDS an item to the END of an array

I hope that helps.

Stay safe and happy coding!

Peter,

These loops and arrays are somewhat more complex. That is why I'm not doing well on the questions etc. Thank you for your patience and help!

Alana