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

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

#1

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

#2

What is the value of remove?


#3

arr.push(item); I give this value


#4

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


#5

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


#6

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


#7

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.


#8

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:


#9

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


#10

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


#11

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);.


#12

How I can do this tell me


#13

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


#14

console shows Nothing


#15

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


#16

Please I stuck on that verify it for me please


#17

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


#18

Nothing I cheked it.


#19

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.)


#20

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