Methods


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
Well, I don’t know why the code won’t work, cause it keeps showing that "TypeError: name.push is not a function"
can anyone help me figure it out?

var name = [];
name.push(“Allen”);
name.push(“Frank”, “Ryan”);
console.log(name);

<do not remove the three backticks above>

#2

Hi @allenkaojr,

Thank you for asking this question! I tested your code, it looked fine based on the syntax but it really throws out error.

What you can do is:

Change the variable’s name to another name, other than the word name itself.

Because the variable name is reserved for other purpose:

You can read more discussion on these:


If you change your code to something like this:

var testing = [];
testing.push("Allen");
testing.push("Frank", "Ryan");
console.log(testing);

It will work.

Hope it helps :slight_smile:


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.