I have code that performs calculations by looking up values in my array of arrays using keys. Here is what I am trying to achieve:
For example, if the score value is 1, I want to retrieve key 1 from the array. There is also a second parameter we can call total. From key 1, we need to find the total within the array and its corresponding value.
It would look something like this: Score = 1 Total = 4 Value = ?
array 1:[1:3,2:6,3:19,4:55];
Therefore, the expected result should be the value 55.
var scores =[{1:[{value:'4'},{score:'1'},{css:'green'}]}];
I have only used one key in the outer array for simplicity.
In order to see how this works, I implemented a loop:
for (var key in scores){
console.log(scores[key]);
var arr = scores[key];
for (var value in arr){
console.log(arr[value]);
var single = arr[value];
for(var val in single){
console.log(single[val]);
}
}
}
The final loop displays the inner array with keys and values as objects.
Now, I am contemplating the best and most efficient way to retrieve these values, especially when performing an operation like:
function getValue(Score, Total){
alert("Key " + value + "is " + this);
alert("Key " + score + "is " + this);
alert("Key " + css + "is " + this);
}
Thank you.