Here is the code to begin with;
data = {
"questions": ["Who", "Where", "How"],
"names": ["Bill", "Fred", "Lindsey"],
"cities": ["Baltimore", "New York", "Chicago"],
"values": [
[
[50, 20, 40],
[40, 90, 10],
[50, 75, 30]
],
[
[33, 57, 100],
[20, 70, 89],
[16, 40, 68]
],
[
[3, 26, 54],
[62, 69, 86],
[23, 81, 98]
]
]
}
function sortObject() {
var values;
var question = data.questions.indexOf("Who", "Where")
var name = data.names.indexOf("Bill");
var city = data.cities.indexOf("Baltimore");
values = data.values[question][name][city]
console.log(values)
}
sortObject()
I would like to be able to return the results for both "Who" & "Where" whilst excluding "How".
So the final result would be [50, 33].
I would also like the method to be able to work with an infinite amount of items, so for instance there could be 100 items in the "questions" array and I would be able to individually pick whichever ones I would like to show regardless of their position inside the array.
I think that I will have to loop through each item and then perhaps do something along the lines of;
for (var question = 0; question < data.questions.length; question++) {
if (data.questions.indexOf() == "Who" || "Where") {
var name = data.names.indexOf("Bill");
var city = data.cities.indexOf("Baltimore");
values = data.values[question][name][city]
console.log(values)
}
}
But this is not working, so I'm not sure where to go from here?
Hope everything is clear, please let me know if you need any more information;
Thanks in advance for any help/advice!