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 trialKatie Dunayczan
8,616 PointsNot 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();
shipping.push(foo);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
1 Answer
Tyrell Jentink
8,415 PointsRemember, 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 = [];
shipping.push(orderQueue.shift());
That should do the magic.