close

[Solved] Uncaught TypeError: data.push is not a function

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Uncaught TypeError: data.push is not a function in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Uncaught TypeError: data.push is not a function Error Occurs?

Today I get the following error Uncaught TypeError: data.push is not a function in javascript.

How To Solve Uncaught TypeError: data.push is not a function Error ?

  1. How To Solve Uncaught TypeError: data.push is not a function Error ?

    To Solve Uncaught TypeError: data.push is not a function Error Your data variable contains an object, not an array, and objects do not have the push function as the error states. To do what you need you can do this

  2. Uncaught TypeError: data.push is not a function

    To Solve Uncaught TypeError: data.push is not a function Error Your data variable contains an object, not an array, and objects do not have the push function as the error states. To do what you need you can do this

Solution 1

Your data variable contains an object, not an array, and objects do not have the push function as the error states. To do what you need you can do this:

data.country = 'IN';

Or

data['country'] = 'IN';

Solution 2

I think you set it as

var data = []; 

but after some time you made it like:

data = 'some thing which is not an array'; 

then data.push('') will not work as it is not an array anymore.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment