.shift function not working! TypeError: arr.shift is not a function

Tell us what’s happening:

Your code so far


function nextInLine(arr, item) {
// Only change code below this line
arr = arr.push(item);
item = arr.shift();
return item;
// Only change code above this line


}

// Setup
var testArr = [1,2,3,4,5];

// Display code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36 Edg/83.0.478.37.

Challenge: Stand in Line

Link to the challenge:

I think you need to revise a bit your logic. Create a new var that will keep arr then you push item to that new var.

The problem is in your first assignment.
From MDN( mdn - array.push ):

The push() method adds one or more elements to the end of an array and returns the new length of the array

Therefore, after your first assignment, arr contains the length of the array, not the array itself^^

Good luck! :slight_smile:

1 Like

Try this!

arr.push(item);
return(arr.shift(arr[item]));

1 Like

Do not use any assignement (=) and revise the logic as Bam92 said!