0

I made an array of type dataRows which is an interface

dataArray: Array<dataRows>;

then in a function I pushed a dataRows object into it

this.dataArray.push(row)

so why do I get Cannot read property 'push' of undefined in the console?

1
  • 4
    The array mus tbe initialized before accessing it's methods/properties: dataArray: Array<dataRows> = [];. Commented Aug 21, 2020 at 14:41

1 Answer 1

1

You are most likely getting the error Cannot read property 'push' of undefined because your dataArray hasn't been defined yet, and is thus undefined - a blank object with no methods.

You need to initialise it with an empty array, like:

dataArray: Array<dataRows> = [];

to then be able to use the .push method to append your row to it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.