Reputation: 89
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)
Upvotes: 4
Views: 17230
Reputation: 4793
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.
Upvotes: 13
Reputation: 572
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)
Upvotes: 0