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

Andre Chavira
seal-mask
.a{fill-rule:evenodd;}techdegree
Andre Chavira
Front End Web Development Techdegree Student 4,556 Points

How do i place all of the contents within an array into a separate variable??

I know the .shift method takes out the fist in line and places that one within a variable but i cant really figure out how to do it for all of the contents within the array. What should i do?

script.js
var orderQueue = ['1XT567437','1U7857317','1I9222528'];

var shipping.shift('orderQueue');
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

1 Answer

Steven Parker
Steven Parker
229,608 Points

This challenge doesn't ask you to remove "all of the contents within the array". If you actually wanted to do such a thing, you'd first need to decide where you were going to put them all.

But for solving the challenge, you have a syntax issue with the "shift" method. The method doesn't take an argument, but it must be applied to the object that will be shifted. Then, you'll need an assignment ("=") to put the removed item into your variable:

var shipping = orderQueue.shift();