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

Van Young
Van Young
15,136 Points

adding item to variable

How do you add item to shipping variable? shipping,push won't work

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

3 Answers

Steven Parker
Steven Parker
231,248 Points

Theoretically, it could work, if you also removed the item needed from the array at the same time. But this challenge is expecting you to remove the item and assign it directly to the new variable.

So, without duplicating the contents of the array, what array method could you use to remove the first item and return its value?

Van Young
Van Young
15,136 Points

return function?

Steven Parker
Steven Parker
231,248 Points

"Return" is not a function, but a statement used inside a function to end it (and optionally return a specified value). You won't need to make a function for this challenge.

But the lesson introduced some array methods that take items out of an array and return their value. One of them takes the first item and the other takes the last. For task 1, the one that takes the first would be useful.

Van Young
Van Young
15,136 Points

That's the shift function, which I used? I cant add object to variable with the push

Steven Parker
Steven Parker
231,248 Points

No, but you can assign the result of the "shift" to it. And "shift" does not take an argument.

Van Young
Van Young
15,136 Points

I did it, nevermind. But it was seriously a lucky guess