JavaScript JavaScript Arrays Store Multiple Values in an Array Remove Elements From an Array

Natalia Ninou
seal-mask
.a{fill-rule:evenodd;}techdegree
Natalia Ninou
Front End Web Development Techdegree Student 8,151 Points

The array assigned to the variable orderQueue contains a list of order numbers. Declare a new variable named shipping. R

The array assigned to the variable orderQueue contains a list of order numbers. Declare a new variable named shipping...

script.js
const orderQueue = ['1XT567437','1U7857317','1I9222528'];
const shipping = [0]
orderQueue.shift();

1 Answer

Cameron Childres
MOD
Cameron Childres
Treehouse Moderator 10,935 Points

Hi Natalia,

Your code uses const to assign shipping to an array and then separately removes the first element of orderQueue with shift(). Using const locks the shipping variable in to referencing the array [0] you've created, so you won't be able to reassign it to something else. We need to remove the first element '1XT567437' from orderQueue and assign it to shipping (as a string, not an array).

Since the shift() method removes the first element of an array and also returns that element, you can accomplish the goals here with one line:

const orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = orderQueue.shift();
// shipping is now equal to '1XT567437'

The first element of orderQueue will be removed and assigned directly to the variable shipping.

Hope this helps! Let me know if you have any questions.