Categories
JavaScript Answers

How to fix Cannot read property ‘push’ of undefined when combining arrays with JavaScript?

Spread the love

Sometimes, we want to fix Cannot read property ‘push’ of undefined when combining arrays with JavaScript.

In this article, we’ll look at how to fix Cannot read property ‘push’ of undefined when combining arrays with JavaScript.

How to fix Cannot read property ‘push’ of undefined when combining arrays with JavaScript?

To fix Cannot read property ‘push’ of undefined when combining arrays with JavaScript, we should make sure we’re calling push on an array.

For instance, we write

const order = new Array();
order.push(a[n]);

to call order.push to append a new entry into the order array.

Conclusion

To fix Cannot read property ‘push’ of undefined when combining arrays with JavaScript, we should make sure we’re calling push on an array.

By John Au-Yeung

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

Leave a Reply

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