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 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'];
var shipping  = ['1XT567437'];

1 Answer

Florian Tönjes
.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