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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Removing Items From Arrays

Chris Harkin
Chris Harkin
1,104 Points

Removing items from arrays Challenge Task 1

Hi can can any one help am stuck on the first challenge question for this video.

"Challenge Task 1 of 2

The orderQueue array contains a list of customer orders. Create a new variable named shipping -- remove the first item from the array and place it in the shipping variable. "

The error am getting

Bummer! It doesn't look like you stored the first item from the array in the shipping variable.

My Code.

var orderQueue = ['1XT567437','1U7857317','1I9222528'];
orderQueue.shift();
var shipping  = ['1XT567437'];

1 Answer

Florian Tönjes
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 Points

Hey Chris,

the 'shift' method removes the first element of the list and returns it.

This is how one does it:

var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping  = orderQueue.shift();

Also, square brackets are creating a list literal. So when you write ['1XT567437'], you create a list that contains the String '1XT567437'.

Regards, Florian