Skip to content
Advertisement

Javascript cannot change the value of mydata

I have this code:

JavaScript

And after I try to add some values:

JavaScript

I keep getting:

JavaScript

How can I fix this?

Advertisement

Answer

You can’t set a property on null. You need to assign an object to your variable first:

JavaScript

Or all in one go:

JavaScript
Advertisement