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 an Array

Katie Dunayczan
Katie Dunayczan
8,616 Points

Not sure what I'm doing wrong

I don't understand how to take an item out of an array and put it in another array. I assume you save that item in a variable?

var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = [];
var foo = orderQueue.shift();
<!DOCTYPE html>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
<script src="script.js"></script>

1 Answer

Remember, arrays ARE variables. You shouldn't have to create a new variable just to store the value you are moving.

Think of functions and methods as a washing machine... A washing machine doesn't care what you put in, it will always just go through the steps of cleaning clothes, and returns them... Similarly, methods and functions don't care what you pass in, they just return a value.

.shift() returns the value you are dropping; So, you should be able to store that returned value into the destination array:

var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = [];

That should do the magic.