I've built a simple object which simulates a table following the answers to this question: Store a table of data in a JavaScript variable
The modeled table is something like this:
| Tension | Dissonance | Modal |
value_a | 1.234 | 5.324 | 7.24 |
value_b | 3 | 6.341 | 27.3 |
I would like to access and retrieve the Tension, Dissonance and Modal values for a single entry value_a (for example), passing to a function the selected parameter.
So far i tried something like this:
var myObj = {
value_a:{D:3.944,T:1.1606,M:5.3893},
value_b:{D:2,T:6.543,M:5.10},
myMethod: function(params) {
console.log(params);
console.log(this.params); //since this.value_a is a correct expression, i thought this might work, but it doesn't
}
};
I would like to be able to do a call like myObj.myMethod("value_a") and then return the value of [D,T,M] associated with value_a
I tried this way (and i know it doesn't work), but i don't know if it's possible to use a parameter as selector of an attribute.
If not, how could i pass the parameter and return the relative attribute values?