Categories
JavaScript Answers

How to fix cannot read properties of undefined (reading ‘push’) error with JavaScript?

Spread the love

To fix cannot read properties of undefined (reading ‘push’) error with JavaScript, we should make sure we’re calling push on an array.

For instance, we write

const arr = [1, 2, 3, 4];
arr.push(5);

to call push on arr with 5 to append 5 as the last item of the arr array.

We can check if a variable is an array with the Array.isArray method.

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 *