4

I'm trying to make a system which reads Dota 2 hero data, in this system I have to store a lot of data about each hero (strength gain, int gain, agility gain)(float) and also what their primary attribute is.

This is what I have so far:

const Heroes = { Abaddon: 'Strength', Alchemist: 'Strength', AncientApparition: 'Intelligence', AntiMage: 'Agility', ArcWarden:'Agility', Axe:'Strength', } 

tried this:

const Heroes = { Abaddon: ('Strength','3.4', '2.4', '1.8', true), Alchemist: ('Strength','2.8', '2.3', '1.6', true), } console.log(Heroes.Abaddon) 

The output was just the last value (true)

2 Answers 2

14

You could get creative and use Enums like Java uses them, for more than a way to rename integers like many other languages. Or you could simply use a standard JavaScript object like this:

const Heroes = { Abaddon: { primaryAttribute: 'Strength', attributeGains: { strength: 3.4, intelligence: 2.4, agility: 1.8 } }, Alchemist: { primaryAttribute: 'Strength', attributeGains: { strength: 2.8, intelligence: 2.3, agility: 1.6 } } }; 

Accessing the values are as simple as you would expect.

console.log(Heroes.Abaddon.primaryAttribute); console.log(Heroes.Alchemist.attributeGains.agility); 

I'm not sure why you are in need of an Enum specifically, but in the end, you will be making a complex but standard JavaScript object.

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

2 Comments

This is exactly what I was looking for, to clarify I wasn't looking for an enum specifically, it was just the only way that I knew how to do this sort of thing.
Glad I could help.
0

You can't do this with JavaScript. The parentheses are just extras. Try using arrays:

const Heroes = { Abaddon: ['Strength','3.4', '2.4', '1.8', true], Alchemist: ['Strength','2.8', '2.3', '1.6', true], } console.log(Heroes.Abaddon) 

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.