Categories
JavaScript Answers

How to fix Uncaught TypeError: data.push is not a function with JavaScript?

Spread the love

Sometimes, we want to fix Uncaught TypeError: data.push is not a function with JavaScript.

In this article, we’ll look at how to fix Uncaught TypeError: data.push is not a function with JavaScript.

How to fix Uncaught TypeError: data.push is not a function with JavaScript?

To fix Uncaught TypeError: data.push is not a function with JavaScript, we should make sure data is an array.

For instance, we write

const data = [
  {
    name: "ananta",
    age: "15",
    country: "Atlanta",
  },
];

data.push({ name: "Tony Montana", age: "99" });
data.push({ country: "IN" });

to declare the data array.

And then we call data.push to append new entries into data.

Conclusion

To fix Uncaught TypeError: data.push is not a function with JavaScript, we should make sure data is an array.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

One reply on “How to fix Uncaught TypeError: data.push is not a function with JavaScript?”

Leave a Reply

Your email address will not be published. Required fields are marked *