Hey tiaan,
Glad to be in touch with you - seems like you’re always working on something interesting.
I played around with your code and with a couple minor adjustments and this is what you need:
let shoes = "a1g1r2”; // just for the example
let xaxis = {
a1g1r1: [30, 30, 15, 15, 10],
a1g1r2: [35, 35, 15, 10, 5],
a1g1r3: [35, 35, 5, 20, 5],
a1g1r4: [40, 40, 5, 10, 5],
a1g1r5: [45, 45, 0, 10, 0],
}
var a = xaxis[shoes][4]; // a will get the value 5
Your original code had this:
var a = xaxis[5](shoes);
This gets interpreted as a function because of the parentheses: (shoes)
So, as you can see in my code, I got rid of the parenthesis so that xaxis is treated as an array, and I put shoes as the first index, or key.
Then, keep in mind that in Javascript, a numeric index needs to be zero-based. So try this:
var a = xaxis[shoes][0]; // a will get the value 35
To get the whole array of values shoes:
var arr = xaxis[shoes];
Using the example above:
let shoes = "a1g1r2”;
var arr = xaxis[shoes];
// arr gets the array: [35, 35, 15, 10, 5]
If you want just one specific value from the array:
let shoes = "a1g1r2”;
var arr = xaxis[shoes];
var value= arr[4];
// value = 5
And putting it all together in one line (as in the code example above):
let shoes = "a1g1r2”;
var a = xaxis[shoes][4]; // a will get the value 5
// a = 5
I hope this helps.
See you around the forum,
Yisrael