JavaScript Function error: method is not a function

Hello, I’m new learning JavaScript, and when I perform some functions, sometimes I get the following error: “Method/Object is not a function”. I.E. I’m trying to push an object within an array, so I use array.push(obj) within the function, but I always get that error message. Thanks in advance for your help, have a nice day! :slight_smile:

My first guess is that perhaps the array variable has been initialized/given a the wrong type. for example:

var array = " ";
array.push(“test”);

This would give the error you are mentioning because the array variable has been initialized as a string by the =" "; after the variable. And strings do not have the push() method available to them. This following code would work:

var array = [ ];
array.push(“test”);

As a quick helper tip, it is helpful if you post the code snippet that you are having trouble with.

Hope this helps!