Please excuse my inability to accurately describe what it is I am after. This in ability has made it very difficult to search for an answer, thus I am asking now.
I have an object (data.drivers) which contains a bunch of lap information.
I am looping through this object to update already displayed information, but would like to condense my code and be able to loop through the fields rather than write the same code for every possible field.
Problem is I do not know how to get the value from i by refering to it with a variable. For example:
$.each(data.drivers, function(pos, i) {
var driver_position = i.position; // this and much more would happen for 9 fields
alert (driver_position);
});
This works.
But what I would like to do is this:
$.each(data.drivers, function(pos, i) {
var fields = [ 'position', 'name', 'laps', 'lapTime', 'pace', 'difference', 'elapsedTime', 'fastLap', 'eqn' ];
$.each (fields, function (ii, field) {
alert (i.field);
});
});