Please help, TypeError: remove.shift() is not a function

Tell us what’s happening:

Your code so far

function nextInLine(arr, item) {
  // Your code here
  var remove = arr.push(item);
 
  return remove.shift();  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

**Link to the challenge:**
https://www.freecodecamp.org/challenges/stand-in-line
1 Like

What is the value of remove?

1 Like

arr.push(item); I give this value

function nextInLine(arr, item) {
// Your code here
var remove = arr.push(item);

I see you code. What is the actual value of remove after that operation. Test it using the console.

1 Like

It gives me an error, I don’t understood what I was doing wrong.

I’m trying to help you see where the error is coming from. Try using console.log() to look at what the value of remove is.

function nextInLine(arr, item) {
// Your code here
var remove = arr.push(item);

return remove.shift();
}

console.log(nextInLine([1, 2, 3], 7));

I use this code, but again error :frowning:

I know. I’ve seen it every time you’ve posted it.

Ok can you do this and tell me what is wrong please

I’ve told you what you need to do as a first step to debug the problem. Look at what the value of remove is after var remove = arr.push(item);.

How I can do this tell me

Use a console.log statement after that line and look at the console.

console shows Nothing

Either you don’t have a correctly written console.log statement in the right place, or you aren’t looking at the right console.

Please I stuck on that verify it for me please

You are assigning remove the value returned by arr.push(item). What does the .push() function return?

Nothing I cheked it.

If it doesn’t return anything, then remove is undefined. .shift() is an array function. You can’t shift an undefined value.

(But it does return something.)

Why it returns me nothing when I use push
I gave as a parameter an array