HeroName = new Hero()
HeroName.Spells = [];
HeroName.Spells[0].Type = [];
This doesnt work =( , even if I try new Array() or anything else. Is it not possible to do arrays within arrays? This is what I was going for:
HeroName.Spells[0].Type[0] = new DmgSpell();
HeroName.Spells[0].Type[1] = new Buff();
I know I can do something like
HeroName.Spells[0][0] = new DmgSpelL();
HeroName.Spells[0][1] = new Buff();
But this doesn't make it as easy to read
Am I doing something wrong? I've tried every possible combination I could think of and using google to search 'array within an array' gives me other results that don't help me. Any help is greatly appreciated
You missed a step. You haven't declared HeroName.Spells[0]
to be an object, so you can't a Type
property to it, because it doesn't exist. This works:
HeroName = new Hero();
HeroName.Spells = [];
HeroName.Spells[0] = {};
HeroName.Spells[0].Type = [];
Set HeroName.Spells[0] as an Object, otherwise, it is undefined
. undefined
can't have any properties.
HeroName.Spells[0] = {};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With